oamSet modifying sprite ids
Posted: Sun Mar 08, 2009 4:00 am
We've written a Sprite class to handle sprites behind a layer of abstraction. In another class, we create a few sprites sequentially using our Sprite::Sprite() constructor and the new keyword:
Sprite::Sprite()
If we print out the member Sprite::spriteId (a u8), they look fine until after the third one is made. It seems like oamSet, the only thing that should interact with spriteId, is changing that Id somehow.
Inside of our second class "Inventory"
If we write a iprintf statement after each sprite is created, their IDs show up fine up till the third is created. Here is what it looks like:
- Each number represents a sprite id. Each line has a one more than the previous because we're printing out new lines after another sprite is created.
Our Questions and concerns:
- What does oamSet() do, and can we have the code for it? We would like to see what it does so we can possibly know what we can do differently.
- We are confused as to how the spriteIDs are being changed. This is causing us difficulty because our collision algorithm is being affected by it implicitly. We are testing the wrong sprites because due to the ID changing, our SpriteEntry* pointers are being altered in a strange way.
Oddly enough, the sprites do appear on the screen correctly...
Any help and input is greatly appreciated.
Sprite::Sprite()
Code: Select all
Sprite::Sprite ( string name, u8 screen, SpriteSize size, u8 prior, u16 xPos, u16 yPos, u8 width, u8 height )
{
this->screen = screen;
setupSprite(name);
assignId();
sprite = &oamMain.oamMemory[spriteId]; //sprite is a spriteEntry pointer, oamMemory is a pointer to
assignPalette();
sprite->x = xPos;
sprite->y = yPos;
sprite->palette = palId;
this->size = size;
this->height = height;
this->width = width;
this->priority = prior;
//oamAllocateGfx returns a u16 pointer gfxindex is just a u16 need to make conversion
if(screen == 0)
{
gfxPtr = oamAllocateGfx ( &oamMain, size, SpriteColorFormat_256Color );
}
else
{
gfxPtr = oamAllocateGfx ( &oamSub, size, SpriteColorFormat_256Color );
}
oamSet(&oamMain, spriteId, sprite->x, sprite->y, 0, palId, size, SpriteColorFormat_256Color, gfxPtr, -1, false, false, false, false, false);
dmaCopy(spriteTiles, gfxPtr, width*height);
}
Inside of our second class "Inventory"
Code: Select all
spriteR1C1 = new Sprite("invR1C1", 0, SpriteSize_64x64, 0, 0, 100, 64, 64);
spriteR1C2 = new Sprite("invR1C2", 0, SpriteSize_64x64, 0, 64, 100, 64, 64) ;
spriteR1C3 = new Sprite("invR1C3", 0, SpriteSize_64x64, 0, 128, 100, 64, 64);
// Breaks here after the third sprite is created
spriteR1C4 = new Sprite("invR1C4", 0, SpriteSize_64x64, 0, 192, 100, 64, 64);
spriteR2C4 = new Sprite("invR2C4", 0, SpriteSize_64x64, 0, 192, 164, 64, 64);
Code: Select all
s1 s2 s3 s4 s5
0
0 1
0 1 2
0 3 2 3
0 4 2 4 4
Our Questions and concerns:
- What does oamSet() do, and can we have the code for it? We would like to see what it does so we can possibly know what we can do differently.
- We are confused as to how the spriteIDs are being changed. This is causing us difficulty because our collision algorithm is being affected by it implicitly. We are testing the wrong sprites because due to the ID changing, our SpriteEntry* pointers are being altered in a strange way.
Oddly enough, the sprites do appear on the screen correctly...
Any help and input is greatly appreciated.