Sign in to follow this  
boehmz

Typecast SDL_Rect to floats?

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
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

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