Currently, my game using some pixel detections.
For exemple, for sprites, i retrieve the pixel of its position.
When i move it, the position values have some decimals like :
thePixel = new vector(position.X, position.Y);
//thePixel = (52.2451, 635.2642)
so i have to Round These values
thePixel = new vector((float)Math.Round(position.X, 0), (float)Math.Round(position.Y, 0));
//thePixel = (52, 635)
I would like to know if there are some other ways to get perfect position (means, without decimal) without Rounding them.
Is it maybe a moving method problem ?
Thx for reading, hope you can help.
You can’t really get around the need to round your values, but you can make it a lot nicer to code by using an extension method:
(As you can see, personally I prefer
FloortoRound. I also have one forCeiling.)Then you can just use it like this:
Of course, if you’re doing per-pixel collision detection – your collision maths should probably be integer-based (not stored as
floatin aVector2). You could usePoint. Turns out I have an extension method for that too:Then:
Or possibly: