Monday, November 9, 2009

Sprite Field Coordinates

Since the Super Nintendo's OAM (object attribute memory) uses a 9-bit x and an 8-bit y screen coordinate, and the screen is 256x224 pixels big, you may think 16-bit field coordinates is the best approach since the top 8 bits will be what screen, and the bottom 8 bits will be what pixel of the screen, but there is a catch. You'd only be able to increment using whole numbers like 1 and 2 pixels per frame. If you need something inbetween like 1.5 pixels per frame you need decimal bits. If you do 16-bit whole numbers and 16-bit decimals such as this:

ssssssssttttpppp dddddddddddddddd
s: screen
t: tile
p: pixel
d: decimal

it will require 32-bit math which the 65816 isn't very good at. Thankfully there is a better way of doing this:

ssssttttppppdddd
s: screen
t: tile
p: pixel
d: decimal

This is not just optimistic because it uses 16-bit math which the 65816 IS good at. It also makes sprite-tile collision way easier. All you need to do is combine both top bytes of both x and y coordinates to calculate the correct tile number the sprite is overlapping.

No comments:

Post a Comment