#49269 - blacksun - Wed Jul 27, 2005 11:31 pm
I have a little tic-tac-toe game that uses 2 different sprites. I have a function that when the user presses A the X sprite will be placed and when B is pressed the O sprite is placed. This works for the most part. However, when the user inputs two of the same sprites at the beginning the rest of the sprites placed will be of that sprite. Their tile index changes accordingly though. I have the X sprite at 512 and O at 514 because they are 8x8, 256 color in Mode 3.
Another problem is if the O sprite is added first, then an X sprite is added, it swaps the images but keeps the index the same.
So here is the code that I have for these two functions.
numOfSprites is a global variable that updates before the sprite is added.
OAMData3 is the address 0x6014000
Another problem is if the O sprite is added first, then an X sprite is added, it swaps the images but keeps the index the same.
So here is the code that I have for these two functions.
Code: |
void AddSprite(int x, int y, int type)
{ u16 i; int index = numOfSprites - 1; u16 spriteIndex; sprites[index].attribute0 = COLOR_256 | SQUARE | y; sprites[index].attribute1 = SIZE_8 | x; if(type == 1) { spriteIndex = 512; for(i = (index) * xDim * X_FRAMES; i < (xDim * X_FRAMES) * (index) + (xDim * X_FRAMES); i++) OAMData3[i] = xData[i - (index) * xDim * X_FRAMES]; } else if(type == 2) { spriteIndex = 514; for(i = (index) * oDim * O_FRAMES; i < (oDim * O_FRAMES) * (index) + (oDim * O_FRAMES); i++) OAMData3[i] = oData[i - (index) * oDim * O_FRAMES]; } sprites[index].attribute2 = spriteIndex; } |
numOfSprites is a global variable that updates before the sprite is added.
OAMData3 is the address 0x6014000