Jump to content

  • Log In with Google      Sign In   
  • Create Account

Frame Independent Motion/Animation in SDL


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
4 replies to this topic

#1 MrTheFoxx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 29 January 2012 - 12:46 PM

I've done a lot of research to find nothing, so I'm posting here. Here goes nothing.

I have two images: a red circle and a blue circle. I have some controls set up. I want the sprite to swap between the red circle and the blue circle every half second and I want it to move across the screen at the same speed of forty pixels per second, both independent from the frame rate. Can anyone give me a minimal example of this being done in C (not C++ or C#... C)? Thank you. :)

Sponsor:

#2 ncsu121978   Members   -  Reputation: 517

Like
0Likes
Like

Posted 29 January 2012 - 01:21 PM

use the SDL timer class to get the elapsed seconds since last frame

then

x_pos += delta_time * 40.0f;

#3 MrTheFoxx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 29 January 2012 - 01:41 PM

I found something about that while I was Googling, but it has to do with C++. The timer class likely isn't present in C itself because C++ is C with Classes. There has to be some other alternative in C to what is available in C++. Or maybe I could program my own time calculator and integrate that in there...

#4 mhagain   Crossbones+   -  Reputation: 8278

Like
0Likes
Like

Posted 29 January 2012 - 02:02 PM

SDL_GetTicks will give you the number of elapsed milliseconds.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 MrTheFoxx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 January 2012 - 02:31 PM

Thanks! So I can set up some if statements and if the time elapsed is equal to or beyond a certain value, change the animation frame for the player and/or the position? Good. Thanks! :)




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