December 09, 2018, 02:50:48 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
   Home   Blogs Help Search Tags Login Register  
Pages: [1]   Go Down
Author Topic: Question about using Float instead of Int  (Read 7143 times)
0 Members and 1 Guest are viewing this topic.
« on: April 08, 2011, 07:11:43 AM »


i was stumbling about the code, that you use float for your sprites, how come? Im just curious, because the ARM Cpus have no FPU, thus Google says on Android:
"As a rule of thumb, floating-point is about 2x slower than integer on Android devices." It could be even that the device doenst even have an FPU (and to be worse, even no divider ;-).

So one Question that arises from me, why are sprites then in Float and not in INT ? (Thought float was used in opengl or any other 3d engine)?


Mattias Gustavsson

Respect: 58
Offline Offline

Posts: 94

« Reply #1 on: April 12, 2011, 01:05:40 PM »

Well, at an early stage of the development, I did actually use integers for sprite positions etc. The reason I changed it, was because I noticed while making games, that I often had to keep track of, for example, a characters x and y position (which had to be floats, as I'm deciding how far to move things depending on the time elapsed since last frame, to get framerate independent movement) and then every frame pass it to the sprite. By changing the sprite position to float, I could just store the positions of the characters directly in the sprite, and that was a bit neater.

There's a few different ways to solve this... you could change the sprites to use integer, and leave it up to the game to store correct positions and pass them to the sprites. Or, you could have the sprites use a fixed-point datatype, which means it would work pretty much the same as it does now, as the floating precision you'd get in a float is not really relevant in this particular case.

Let me know if you'd like any more details on this (or if you need help implementing a fixed-point type, should you opt to go down that route)  Smiley
« Reply #2 on: April 12, 2011, 01:38:11 PM »

Ohh its ok. Since im still waiting for my android to get the 2.3 update for the full c/c++ Api, i cant really test this speed issue. We will see, when i get the baby compiled, until then i still code on Windows to get pixie better to know. Wink
Pages: [1]   Go Up
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!