Sign in to follow this  
Sanio

Smooth movings in game

Recommended Posts

Sanio    122
Hi! I'm started to write my first game with SDL. And the first problem I have is moving of sprites in 2D game world. First of all I decided that more correct way to calculate new positions is like: float posX = 0.0; float speed = 0.1; float frameTime; ..... posX = posX + speed*frameTime; .... where frameTime is the delta-time between frames. This is right way since object allways moves correct distance independently of the delta-time. But the problem is that all my sprites blinking on the screen when they moving with low speed. Is there any solution to smooth movings of sprites? Maybe it is simmilar to those interpolation algorithms to smooth сurve ( e.g. surface)? :) My code and CodeBlocks Project (for MinGW): http://rapidshare.com/files/174176159/SmoothMovement.zip.html

Share this post


Link to post
Share on other sites
HomerSp    126
Quote:
Original post by Sanio
But the problem is that all my sprites blinking on the screen when they moving with low speed.

That doesn't sound like it's related to the smooth movement. Are you sure there's not anything else that's causing it?

Share this post


Link to post
Share on other sites
Sanio    122
Quote:
Original post by HomerSp
Quote:
Original post by Sanio
But the problem is that all my sprites blinking on the screen when they moving with low speed.

That doesn't sound like it's related to the smooth movement. Are you sure there's not anything else that's causing it?


Which other things can cause my sprites to blink? Maybe "blinking" is not correct word, more correct to say "sprites moving with delay". It depends on speed. For example if I increase speed sprites moving more smoothly, but if speed is low then they moving with delay:

posX=400px
pause = 0.5 sec
posX=402px
pause = 0.6 sec
posX = 403px
pause = 0.5sec
.....
and so on.

And that is not good looking thing for game objects which moving very slowly.

But, maybe the problem in discrete screen precision and I can do nothing...

Share this post


Link to post
Share on other sites
Sanio    122
I found some possible explanation of "moving jumps":

The problem in nonlinearity of FPS. For example my object should move with speed V. So, object's position calculated as P = P + V*frameTime. If frameTime is constant value then object should move in constant distance and it should look smoothly. But frameTime is not constant value (e.g it can vary from 0.003ms to 0.014ms) and then object moves with small jumps.

Am I right? And Is there any way to smooth such moving jumps? :)

Share this post


Link to post
Share on other sites
Sanio    122
Quote:
Original post by HomerSp
Did you have a look at this?
http://www.gamedev.net/reference/articles/article1382.asp


Thank you! I hope this will help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this