Announcement

Collapse
No announcement yet.

Time service to speed up entire game

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Time service to speed up entire game

    Hi everyone,
    I would like to know if there is class or a service available which allows me to control the time in the game so every entity moves at double or half speed.

    This is really useful for gameplay testing, skipping some actions quickly or slowing down others.

    Currently I have a Slider which allows me to modify the speed one entity moves, I could also make a static property to control the whole game, but this would require to modify all the code related to time between frames in order to multiply by that property.

    So I was wondering whether there is a service which allows me to do the same without changing most of the code.

    Thanks

  • #2
    Hey Anddon, how are you modifying the speed of the single entity?

    Comment


    • #3
      Basically, there is a component WorldObject, which has generic attributes such as the name, the health and the speed, which I called generic speed. After that, I have created a GUI slider which, when its value changes, updates the speed of the entity marked as selected (I am using tiles, so defining the entity we point at with the mouse is trivial).
      Finally, when I move an entity through its transform, or a game action, the speed of a specific action time lapse (timespan, etc.) is multiplied by that generic speed. So, obviously, it moves faster or slower when that value changes.
      The problem is that you are forced to add that line of code to wherever you would like to control the speed, so it is not independent from the code.

      By the way, I have just realised that the timespan you receive in each Update comes from App,Update, so we may add the speed property there and modify the timespan passed onto all behaviors. I am not sure if it is possible or recommendable but I will give it a try.


      EDIT: About a totally different subject, I have noticed that, when resizing the window game to full screen, the GUI places properly, but not the hitboxes (I don't know if the name is right), even after calling Layout.PerformLayout(). So, when I click a button, it may select one button from below or nothing at all. Am I missing something or is this a bug?
      Last edited by anddonram; 05-09-2017, 12:52 PM.

      Comment


      • #4
        Hi anddonram, there is no built-in service in Wave to control the game speed, so I think you are using a nice approach with a WorldObject to control that for you.
        You could try some sort of hierarchy in your game entities in order to avoid the forced line of code to handle the speed.

        Have a nice day, Juan.

        Comment


        • #5
          Hi Juan,
          What about the App.Update option? As far as I am concerned, all the Behavior Update methods are called from the game.UpdateFrame(elapsedTime). Is that right?
          So, could I modify the App class and add the speed and do something like
          Code:
          game.UpdateFrame(elapsedTime*speed)
          or similar. The problem is that I do not know if that elapsedTime is used internally for other purposes, resulting in a wrong behavior overall (for example, the method Draw also uses a TimeSpan, and I don't know if it is the same)

          Another option I thought was to extend the Behavior class by adding a static speed and then calling the original Update with the modified TimeSpan
          Code:
          protected override void Update(TimeSpan gameTime)
                  {
                     TimeSpan newTime=TimeSpan.FromSeconds(gameTime.TotalSeconds*speed);
                     base.Update(newTime);
                  }
          All behaviors then should extend this.

          I am specially interested in the first option viability, so that I can understand better the engine (also requires less effort), but I am not sure about the consequences of messing with the TimeSpan and the game main loop.

          Have a nice day, Andrés

          Comment


          • #6
            Hi anddonram!

            I personally prefer the first approach you described using a WorldObject, this way you have fine-grained control over the entities you want to accelerate and the ones you don't.

            The extended behavior you posted is what I was refering to in my last post regarding "hierarchy in your game entities" to avoid code duplication. So using a combination of the WorldObject which manages the speed inside the extended behavior of your game entities you could solve the problem.

            But if you just want this for gameplay testing or to be able to skip some parts of the game or certain scenes I will go with the idea you just post, modify the gameTime globally to speed up everything. You wouldn't break anything inside the engine. In fact, we are currently using a similar trick in our visual testing system to speed up the execution of wave engine visual tests.

            I think both are nice solutions and you won't be messing with the engine in none of them

            Comment


            • #7
              Hi jacano,

              The last thing you said was exactly what I was looking for. And I already had the first solution implemented.

              In fact, I think both solutions are compatible and help in different ways for testing and polish the game flow, so I will combine them for even greater control.

              Thank you very much for your response.

              Comment

              Working...
              X