Pixel-perfect jitter-free animation
Here's a thing I cannot wrap my head around:
When we are talking about low-resolution pixel art, there is a subcategory that deals with pixel perfection: Like in the olden days you are restricted to a grid and each pixel can only take up a complete square on that grid. No half-pixel shifts, no rotated pixels, no mixed resolution.
Now let's talk about animation for pixel perfect games: I can easily get smooth animation if I move a sprite by integer speeds: 1 pixel per frame, 2 pixels per frame, etc. For slower speeds I can stretch my movement over multiple frames: 1 pixel per 2 frames, 1 pixel per 3 frames, etc.
This however is very impractical since the few available speeds are very limiting. So the solution to my understanding is to use float speeds, which of course results in float positions, which are rounded before drawing the sprite to the pixel grid. This allows for basically any movement speed and can also deal with the problem of inconsistent frame rates by using variable movement that is adjusted by the current frame rate.
Here's the problem though: If I am living in the world of low-resolution perfect pixel art, this rounding to full pixels can and will introduce ugly jitter effects. The lower the resolution, the more apparent it becomes.
Consider this:
My sprite speed is 1.01 pixels per frame. Since we are dealing with rounded positions, my sprite will move at a steady and smooth 1 pixels per frame for the first 50 frames because we are rounding down (0.0, 1.01, 2.02, ..., 49.49). As soon as the sprite reaches frame 51, we start rounding up (50.50 becomes 51), so for that single frame the sprite will move 2 pixels (from 49 to 51), which can be perceived as a movement hiccup. Afterwards it will run smoothly for another 100 frames until the next change from rounding down to rounding up occurs and we have another hiccup.
What I cannot get my head around is how the games from the olden days ran so smoothly? I don't recall Super Mario Bros or Super Metroid having any of those jitter effects, they were running absolutely smoothly, so what gives? At least for SMB, I know that they had some clever way of storing the fractional parts of the sprite positions, so they must have used the float-and-round-technique.
I only recently started thinking about this topic, because I have a hard time understanding why Game Maker Studio is able to pull off butter-smooth movement and pixel-precision at the same time, while Godot seems to be struggling with this. Anybody with in-depth knowledge of the two engines who can tell me what the magic trick is that I am missing?
There must be a solution to this because there are many pixel-art games, that are running absolutely smoothly and obey the rules of the perfectly aligned pixel.
Edited 24 Jan 2022. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 7 · 90% up
- Kind
- Text
- ID
- sb9351