There are many ways to skin this cat, but the easiest may be to create a doppelganger sprite, constrained to the discrete coordinate space. That is, make your actual sprite invisible, and set a second sprite that follows the main sprite with discrete movement.
- Make your main sprite invisible: set
- Create a second sprite
- Make the second sprite follow the main sprite in one of your
- From simple integer division, we know that
round(x / y) * y % y == 0, so set the sprite's coordinates accordingly. Use whatever rounding function is appropriate.
sprite.x = Math.round(x / SOME_FIXED_VALUE) * SOME_FIXED_VALUE
sprite.y = Math.round(y / SOME_FIXED_VALUE) * SOME_FIXED_VALUE
I've kept the main sprite visible so you can see what's going on, as you move the main sprite with the mouse. Sprites from http://opengameart.org/content/squares
I consider this approach easiest as you don't have to hack away at any physics routines or override anything, and it plays well with any existing physics code you may use.