Original Post
Hi, I'm animating a tile-based game in Java and am having a problem. My animation works by multiplying the time elapsed since the last game tick by a set number, and then incrementing the image's x or y location by that number. Fairly standard. Now, my tiles are 16x16 pixels, and to stop the sprite moving after 16 pixels, I simply use: float xDist = 0; //check for sprite stop float x = 0; //player's x loc private static final int TILE_DIM = 16; . . . if ((xDist >= TILE_DIM ) || (xDist <= -TILE_DIM)){ xDist = xDist % TILE_DIM; stop(); } else { x += dx * elapsedTime; xDist += dx * elapsedTime; } It's not very elegant, but I just check that if a number, xDist, is greater than 16, mod it by 16 and stop the animation, else increment x and xDist. It kind of works, but unfortunately it won't always move 16 pixels -- sometimes it'll be offset by two or three pixels which, whilst doesn't sound a lot, is noticeable. After a couple more moves it will work itself out, but another few more moves it'll be out again. This isn't really accurate enough. If anyone has any ideas on how to keep the sprite moving 16 pixels ONLY each turn, I'd appreciate it. Cheers, NegativeSpace