Using floats instead of ints for X/Y position and velocity -- performance loss?
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?
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
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement