• Advertisement
Sign in to follow this  

Typecast SDL_Rect to floats?

This topic is 3323 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got a game going in SDL with a main character and enemies. I got the main character and his bullets moving at a good speed I like. Right now the enemies just move towards the main character at 1 pixel per frame. This turns out to be faster than I would like. The easiest way to slow down the enemies I would think is to move them a decimal amount each frame, but members of SDL_Rect can only be integers, so moving them .2 each frame is the same as moving them 1 unit. Should I typecast the SDL_Rect or completely change my logic? The only other option I can think of is to use timers to move them 1 pixel per second(this will be slower since the game is running at 30 fps). Is there another better way that I am not thinking of? How do profesional game makers handle movement?

Share this post


Link to post
Share on other sites
Advertisement
The typical approach is to use a floating-point representation for the simulation, and to convert to integers only as necessary (e.g. for rendering).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement