x,y position variable type?

BlitzMax Forums/BlitzMax Beginners Area/x,y position variable type?

Jaydubeww(Posted 2010) [#1]
So, my x and y position variables...should they be kept as integers or floats? I'm assuming the answer would be integers considering its quite hard to notice .1 of a pixel movement let alone know how it would affect pixel perfect collision detection.

Thanks!


plash(Posted 2010) [#2]
You'll certainly notice the difference when rendering.
Unless you're emulating 8-bit graphics, use floats.


orgos(Posted 2010) [#3]
You must use Float to get some smooth move

For example, a planet orbiting, the x and y as float get a smoothed movement.

You can get another rare situation with particles effects if you use integer.


_Skully(Posted 2010) [#4]
So, my x and y position variables...should they be kept as integers or floats? I'm assuming the answer would be integers considering its quite hard to notice .1 of a pixel movement let alone know how it would affect pixel perfect collision detection.


Your right, it is hard to notice .1 of a pixel movement which is why you need to use floats. Its easy to notice a full pixel movement!


Foppy(Posted 2010) [#5]
To keep track of the position of an object that is moving at a speed of 1.5 you need to store that position in floats, otherwise you lose the .5 part.

Apart from that, Blitz Max actually draws images at non-whole positions, using anti-aliasing.

(As explained here http://www.2dgamecreators.com/tutorials/gameprogramming/images/T1_Images.html under "Fractional positions")

You could also store the position as floats to get movement at the correct speed, but use the integer (rounded) values of those floats in drawing, in order to avoid the anti-aliasing, if that is what you want.


ima747(Posted 2010) [#6]
It depends on what you're doing to/with the positions. As mentioned motion will be smoothed dramatically by using floats. However for something that doesn't move, or doesn't need to move smoothly (a piece of scenery you recycle) an int would theoretically be an option... however DrawImage() takes floats as it's input values for positions, so the calculation savings of using ints would be lost as they would then be converted to floats every draw anyway...

So unless you know you need an into for position information for a specific reason (never say never...) then I would side with the group as well and say floats should be your default. You don't have to use the space between the whole numbers, just pretend they're ints if you like, but at the very least it will prevent int->float conversion when you draw. You'll also be ready if/when you want to smooth out your animations etc.


Jaydubeww(Posted 2010) [#7]
Thanks guys, it makes perfect sense now. This was a question that was sitting in the back of my mind for about a month now...I did create a test program a while ago to find out whether or not you had to use whole numbers. Really I just asked because I wanted your expert advice ;)


N(Posted 2010) [#8]
Although it's been mentioned above about using floats for positions, I recommend rounding X/Y values when passing them to DrawImage and especially DrawText, otherwise you're pretty likely to end up with images being blurry thanks to filtering.


Who was John Galt?(Posted 2010) [#9]
I prefer the slight blur of filtering to the judder of rounding pixel values when using fractional positions. It may be worth investigating the use of super-resolution images with fractional positioning, i.e. try making your image twice the screen resolution.


ima747(Posted 2010) [#10]
IMO it depends on the application how blurry you get if you don't round, and also how juddery you get if you do. Never a 1 size fits all solution :0)

I will say I never really notice the blurring except on text, but I also don't do a lot of stuff in 2D at the moment, and when it do it tends to move pretty quickly, and I tend to force it to opengl for more consistency between mac and PC.

Everyone's milage will vary.