#48669 - lewisrevill - Thu Jul 21, 2005 5:52 pm
Im coding a GBA game in Mode 4 and if a sprite gets moved partly off screen it either messes up or dissapears. Can you help?
#48680 - tepples - Thu Jul 21, 2005 6:54 pm
Five bucks says you're not properly masking off the upper bits of the X and Y coordinates. If you don't, then the 1-bits that represent negative numbers will overflow into the parts of the OAM bitfields that specify sprite shape, size, rotation, and the like.
Hints: y & 0x00FF and x & 0x01FF.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#48743 - ScottLininger - Fri Jul 22, 2005 1:14 am
You may already know this, but negative sprite locations are invalid, so you have to take advantage of the 512x256 pixel "wraparound universe" that the gameboy uses.
So, if you want the sprite to be 10 pixels off the left (x location of -10), then you set it's x value in memory to be 512 - 10 = 502.
Plus the masking stuff that Tepples said.
Cheers,
-Scott
#48908 - lewisrevill - Sun Jul 24, 2005 12:13 am
Hey thanks for your reply's guys. I pretty new to this so parden my nieve-ness, but what is this masking business?? is it something in corespondence to this piece of code? :
void CopyOAM(void)
{
u16 loop;
u16* temp;
temp = (u16*)sprites;
for(loop = 0; loop < 128*4; loop++) {
OAM_Mem[loop] = temp[loop];
}
}
please reply
#48909 - Sintax - Sun Jul 24, 2005 12:21 am
That code only moves the OAM copy (which is used to hold OAM data until it can be set during vsync) onto the GBA's OAM memory. If you don't know what any of that means, it doesn't really matter because that's not the code they're talking about.
This is the code I use to moves sprites, and it has the masking stuff that tepples talked about. You should have it too because it looks like you got your sprite code from the same place:
Code: |
oam->attribute[1] &= 0xFE00;
oam->attribute[1] |= (x & 0x01FF);
oam->attribute[0] &= 0xFF00;
oam->attribute[0] |= (y & 0x00FF); |