XNA Creators Club Online
Page 1 of 1 (12 items)
Sort Posts: Previous Next

Slow Motion?

Last post 10/6/2007 2:53 PM by Harald Maassen. 11 replies.
  • 7/31/2007 9:43 AM

    Slow Motion?

    I'm trying to implement a "slow motion" feature in my game, and I was just wondering if there was a XNA standard for controlling gametime.  It seems like the 2 ways to do this would be to (1) have a "motionSpeed" variable that is divided into any relevant time calculation, or (2) in someway indicate via some hook in XNA that time is to be slowed.

    Has anyone implemented this feature in their own game?  Any tips?

    Thanks.
  • 7/31/2007 9:54 AM In reply to

    Re: Slow Motion?

    The way I would probably do it would be to only call the Update() function of my game objects at certain intervals because XNA uses a lock stepping method for controling game updates anyway.

    You could implement an ISlowable interface which you could then apply to any object you wanted to be able to slow down, that way things would be much cleaner and any non-ISlowable objects could carry on updating at normal speed. Although, if I were going to do it this way I'd be tempted to create a second Update() function to still allow some things to be updated every frame.

  • 7/31/2007 10:47 AM In reply to

    Re: Slow Motion?

    There's nothing built in to do this. 

    Personally I would create a global 'speedFactor' variable and divide all time calculations by that value before I used them. Means you have to remember to do it though.

    The problem of missing some calls to Update on a fixed timestep is that you will only be able to evenly implement factors of that speed e.g. for 60fps you will only be able to do 1/2, 1/4, 1/3, 1/5, 1/6, 1/10, 1/12, 1/15, 1/20 speeds. If you go this route remember not to use the elapsed time or gametime that is passed in, but assume that you are still on your regular lock step time.

    Playtest Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 7/31/2007 9:04 PM In reply to

    Re: Slow Motion?

    I recommend you use a factor like ZMan suggested. Another problem with skipping calls to Update is that you will make your slow-motion animations look choppy.

    Imagine a fast-moving object that can travel across the screen in 10 frames. Now say you want to slow that down so it takes 30 frames. If you skip the Updates, then you will end up drawing it in only 10 different positions, but you will see it in each position for 3 times as long. If instead you apply a factor (1/3 for this example) to your elapsed game time when you do your calculations in Update, then your object will move smoothly across the screen, but at 1/3 the speed.

     

    Stephen Styrchak | XNA Game Studio Developer
  • 7/31/2007 10:28 PM In reply to

    Re: Slow Motion?

    Hey,

    Try this:

    protected override void Update(GameTime gameTime)

    {

          float dt = slowMotionScale * (float)gameTime.ElapsedGameTime.TotalSeconds;

          //more stuff...

    }

    Get your time step from dt instead of gameTime.  You lose a bit of functionality, but you get genuine slo-mo =P

  • 8/1/2007 4:21 AM In reply to

    Re: Slow Motion?

    Righteous Tool:

    Another problem with skipping calls to Update is that you will make your slow-motion animations look choppy.



    Yeah, I thought about this immediately after posting the comment =o)

    It would look ok if the objects were moving slowly or not moving by much but for anything else it really isn't a good solution. Do what ZMan suggested, definitely.

  • 8/1/2007 12:44 PM In reply to

    Re: Slow Motion?

    ahem ahem...and my idea is dirt? lol
  • 8/1/2007 12:55 PM In reply to

    Re: Slow Motion?

    Your idea is exactly what I suggested... so no
    Playtest Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 8/1/2007 3:05 PM In reply to

    Re: Slow Motion?

    The problem with just using a speedFactor variable is that your cumulative times will be messed up if you change the speed factor.  We solved this in our DBP project by creating a time controller class that held its own timespans - both real time and modified time.  Then you just update that every frame with gametime, and use the time variables in the time controller to update your objects.

    I coded my own for the library I'm working on - but since the library isn't really worth releasing yet, here's the code file by itself.  Hopefully it's of some use to you.

    http://www.kyleschouviller.com/files/TimeController.zip
    http://www.kyleschouviller.com
  • 8/1/2007 5:39 PM In reply to

    Re: Slow Motion?

    For my game I simply have a gameSpeed float variable that I modify. It is always between 0.0f and 1.0f. 1.0 is 100%. I pass the variable into anything in the game that is affected by speed effects.

    Some pseudocode would be:

    Movement.Y += 3.0 * game elapsed time * gameSpeed;

    XNA QuickStart Engine (3D Game Engine for XNA) | My site
    "I'll be whatever I want to do!", Philip J. Fry
  • 8/4/2007 12:59 PM In reply to

    Re: Slow Motion?

    The ZMan:
    Your idea is exactly what I suggested... so no

    ooooops..... didn't see that you mentioned it.....

  • 10/6/2007 2:53 PM In reply to

    Re: Slow Motion?

    Bit of a late reply, but I was just messing about with this and the following works if you use the gameTime in your calculations:

    protected override void Update(GameTime gameTime)
    {
    // slowmo 33%
    gameTime = new GameTime(gameTime.TotalRealTime, gameTime.ElapsedRealTime, new TimeSpan((long)(gameTime.TotalGameTime.Ticks * 0.33f)), new TimeSpan((long)(gameTime.ElapsedGameTime.Ticks * 0.33f)));
    base.Update(gameTime);
    }
Page 1 of 1 (12 items) Previous Next