Page 1 of 1

how to constrain bodies to integer x/y coordinates

Posted: Sat Oct 08, 2011 1:10 pm
by arahlf
Is there an easy way to constrain a Body to whole-number coordinates? I'm making a pool game, and the balls often end up with coordinates like:

(585.61932373047, 447.06735229492)

When drawing with those coordinates, the image sprites are somewhat distorted because they are not whole numbers. I've tried rounding the body's x/y values post-update, but that is somewhat problematic because it then triggers additional collisions sometimes.

Any ideas or suggestions?

Thanks!

Re: how to constrain bodies to integer x/y coordinates

Posted: Sat Oct 08, 2011 1:17 pm
by bartbes
Simulation-wise it might be better to just round the coordinates while drawing, and have the physics just work with the fractions.
(And rounding is of course math.floor(x+0.5).)

Re: how to constrain bodies to integer x/y coordinates

Posted: Sat Oct 08, 2011 1:34 pm
by Taehl
I agree with bartbes. Round the coordinates you draw them at, but leave the real coordinates alone.

Re: how to constrain bodies to integer x/y coordinates

Posted: Sat Oct 08, 2011 1:35 pm
by arahlf
I'll give that a try, thanks.