This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Nerdy Nights Week 5: sprite position?

Nerdy Nights Week 5: sprite position?
by on (#94013)
So, i'm following this tutorial: ... eadid=7974

It loads the sprite position from $0203. I understand that in the provided examples, in order to make the sprite go Up and Down instead, i have to load from $0200. But why? How can i know the difference between $0203 and $0200?

by on (#94014)
This is defined by the design of the PPU and its OAM table format, which is documented here.

by on (#94015)
Go back and review the previous week:

$0200 is the Y position of the sprite (up and down)
$0203 is the X position of the sprite (left and right)

Sprite Data
Each sprite needs 4 bytes of data for its position and tile information in this order:

1 - Y Position - vertical position of the sprite on screen. $00 is the top of the screen. Anything above $EF is off the bottom of the screen.

2 - Tile Number - this is the tile number (0 to 256) for the graphic to be taken from a Pattern Table.

3 - Attributes - this byte holds color and displaying information:

||| ||
||| ++- Color Palette of sprite. Choose which set of 4 from the 16 colors to use
||+------ Priority (0: in front of background; 1: behind background)
|+------- Flip sprite horizontally
+-------- Flip sprite vertically

4 - X Position - horizontal position on the screen. $00 is the left side, anything above $F9 is off screen.

Those 4 bytes repeat 64 times (one set per sprite) to fill the 256 bytes of sprite memory. If you want to edit sprite 0, you change bytes $0200-0203. Sprite 1 is $0204-0207, sprite 2 is $0208-020B, etc

by on (#94058)
Shame on me! :oops:

ps. What about sprite rotation? Or is this a can of worms for a beginner?

by on (#94060)
NES can't rotate, only flip.

by on (#94061)
Hm, interesting. I had in mind an asteroids-style rotation.

by on (#94062)
You'll just need to use extra tiles for the directions that would be rotated.

by on (#94068)
Thwaite has 9 frames of animation for rotation of missile sprites, from 0 to 90 degrees at 11.25 degree intervals, and flipping extends this to the full circle. You can see the frames in the tile sheet, whose name is tilesets/maingfx.png.

Hardware support for arbitrary sprite rotation wasn't common until the Super FX coprocessor and the fifth-generation (32-bit) systems.

by on (#94069)
vicious wrote:
Hm, interesting. I had in mind an asteroids-style rotation.

This can certainly be done. Sprites can be rotated, it's just not automatic... The most common solution is to have different tiles for all posible rotations. Of course this limits the number of different objects you can have, since there are only 256 tiles available (512 if you use 8x16-pixel sprites, but 256 of those are shared with the background).