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

Started by
3 comments, last by josh1billion 17 years, 8 months ago
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?
Website (with downloads of my games)
Blog (updates on current projects)
Seeds of Time Online has returned!
Advertisement
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
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
The answer is no. Use floats.
Alright, thanks. I was actually expecting the opposite to be the answer. Good to know.
Website (with downloads of my games)
Blog (updates on current projects)
Seeds of Time Online has returned!

This topic is closed to new replies.

Advertisement