how to constrain bodies to integer x/y coordinates

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
arahlf
Prole
Posts: 12
Joined: Tue Sep 13, 2011 2:14 am

how to constrain bodies to integer x/y coordinates

Post 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!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post 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).)
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

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

Post by Taehl »

I agree with bartbes. Round the coordinates you draw them at, but leave the real coordinates alone.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
arahlf
Prole
Posts: 12
Joined: Tue Sep 13, 2011 2:14 am

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

Post by arahlf »

I'll give that a try, thanks.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 42 guests