v0.1 ⌊ALPHA⌉
On this page
  1. In the games the atlas has read
  2. Related
  3. References
  4. Sources

A subpixel is the undrawn fraction of a pixel in a position or speed. It lets things move by less than a pixel per frame, as in a slow walk. The fraction sits beside the whole-pixel position and carries into it when it adds up to a pixel. Its storage and resolution decide which speeds a game can represent.

#In the games the atlas has read

  • Super Mario Bros. stores vertical speed as a pixel byte and a fraction byte, in 1/256 px. Each frame, it adds the fraction into a subpixel byte of the position1. Horizontal speeds are coarser, in 1/16 px/frame2.
  • Sonic the Hedgehog keeps 32-bit 16.16 positions and shifts 8.8 speeds into them, so its motion also resolves to 1/256 px3.
  • Celeste keeps whole-pixel positions plus a float remainder per axis, and moves by the rounded remainder4.

All three draw only the whole-pixel part, so the atlas reports jump heights in whole drawn pixels.

References

  1. ^Vertical motion is 8.8 fixed point; each frame, ImposeGravity adds speed to position, the fraction via the YMF_Dummy subpixel byte, then gravity to speed. T3Xkeeper0/smb1 · src/prg.asm L6666–6687
  2. ^Horizontal speeds are 4.4 fixed point, whole pixels and sixteenths per frame; MoveObjectHorizontally shifts the sixteenths into the subpixel byte. T3Xkeeper0/smb1 · src/prg.asm L6492–6503
  3. ^ObjectFall adds the pre-gravity speed, shifted left 8 bits, to the 32-bit position, so positions are 16.16 and speeds 8.8 fixed point. T3sonicretro/s1disasm · _incObj/sub ObjectFall & SpeedToPos.asm L16–20Sonic Retro, “Sonic Physics Guide: Calculations (Pixel and Subpixel)” · Pixel and Subpixel
  4. ^Celeste's actors sit on whole pixels; MoveV adds the float distance to a remainder, moves by its rounded value, and keeps the fraction. T2Thorson 2020 · Actor BasicsNoelFB/Celeste · Source/Player/Player.cs L935

Sources

Code

Primary

Secondary