Jump to content

  • Log In with Google      Sign In   
  • Create Account


Smooth Sprite Movement


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 neomaycry   Members   -  Reputation: 116

Like
0Likes
Like

Posted 18 July 2013 - 06:57 PM

I am continuing work on a 'space shooter' game in SFML 2.0, and everything is going well.  The question I have pertains to changing the sprite's position using velocity along the 'x' axis (velX) and velocity along the 'y' axis (velY).  Assuming each variable is set to a constant value of 5, the sprite will "skip" pixels until it reaches a new destination equal to its current position plus 5 per game cycle.

 

This creates a rough effect, as the sprite apparently jumps from one position along a diagonal line to the next.  Is there a way to have the game loop render all the "missing" frames between the sprite's old position and its new destination?  This is mostly a cosmetic concern.  The current method looks okay ... I just want to see if there is a "smoother" way of rendering the sprite's position change.

 

Thanks.


Edited by neomaycry, 18 July 2013 - 06:59 PM.


Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 18487

Like
5Likes
Like

Posted 18 July 2013 - 07:52 PM

This creates a rough effect, as the sprite apparently jumps from one position along a diagonal line to the next.  Is there a way to have the game loop render all the "missing" frames between the sprite's old position and its new destination?  This is mostly a cosmetic concern.  The current method looks okay ... I just want to see if there is a "smoother" way of rendering the sprite's position change.

 

Question 1: How frequently are you updating the logic?

Question 2: How frequently are you rendering?

 

You can't display incremental steps any faster than you are rendering.

But you can update your logic faster to make it seem smoother. However, there are two better ways to do it.

 

A) You can update using difference in the time from the last frame (often called 'delta time'). If 'delta time' is a float measured in seconds, then you can update as fast as you like, and still keep consistent movement speeds by doing this: "pos += (velocity.x * deltaTime);". Where 'velocity.x' is the amount of movement in one full second.

 

B) You can use fixed time steps... but then interpolate the position between the separate timesteps during rendering. I've never done that myself (lack of experience), so I can't advise you on that.

 

(Most of those links are talking about online games - but they all also apply to singleplayer games)


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 neomaycry   Members   -  Reputation: 116

Like
0Likes
Like

Posted 18 July 2013 - 08:45 PM

Servant,

 

Your explanation was superb, and the resources you shared are wonderful.  Everything looks beautiful now.  Delta time was the answer :).

 

Thank you!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS