Sign in to follow this  
josh1billion

Using floats instead of ints for X/Y position and velocity -- performance loss?

Recommended Posts

In my 2D game (using Allegro), I decided to use floating point variables instead of integers for my Sprite class's x/y coordinates and x/y velocity. That way, I can have some more control over the sprite's speed. The sprite will have to do everyday sprite tasks in each frame, such as moving (x position += x velocity, and the same for Y), drawing (draw at x/y float coordinates), collision testing, etc. I expect my game to have around.. say.. at least 15 sprites functioning at a time. Will this use of floats instead of ints cause a major impact on performance, or will the speed loss be minor and probably unnoticable?

Share this post


Link to post
Share on other sites
There's one sure fire way to find out -- test it and see.

Make it work, then make it fast. If floats are needed for the level of control you want, then use floats. Worry about performance when your sprites are actually not moving fast enough.

CM

Share this post


Link to post
Share on other sites
From what I know, most modern processors are as fast, if not faster, with floating point math.

That said, you're game is probably going to be so minimal in comparison to any modern game that floating point won't even be noticable. Even in modern games, they all use floats (you kind of have to). I wouldn't even think twice about storing positions as floats over ints if you are targetting PC's. It's no biggy. If you are targetting mobile phones or something, then you may need to look into it more.

Again, I'm no expert but I doubt anything you could write would even suffer anything at all with floats over ints. That's not insulting your work, just saying that as a hobbiest programmer, it's hard to accomplish as much as the big huge games.

Shawn

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