gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > MoveSprite causing garbled sprites (yep, another n00b topic)

#108438 - djmcbell - Wed Nov 08, 2006 8:42 pm

Sorry for yet another pointless topic that will probably be answered inside 30 seconds.

Basically, using the moveSprite function from Patatersoft, code below -

Code:
//Move a Sprite
void moveSprite(SpriteEntry * spriteEntry, u16 x, u16 y)
{
   spriteEntry->attribute[1] &= 0xFE00;
   spriteEntry->attribute[1] |= (x & 0x01FF);
   spriteEntry->attribute[0] &= 0xFF00;
   spriteEntry->attribute[0] |= (y & 0x00FF);
   updateOAM(spriteEntry);
   updateOAM_SUB(spriteEntry);
}


I've added the updateOAM and updateOAM_SUB myself, just to quickly make sure that it works here. And there's a swiWaitForVBlank() in the main code, just after our moveSprite is called. Code for updateOAM and updateOAM_SUB below, but pretty much standard -

Code:
//Update the OAM - OAM_SUB
void updateOAM(SpriteEntry * spriteEntry)
{
   DC_FlushAll();
   dmaCopy(spriteEntry, OAM, 128 * sizeof(SpriteEntry));
}

//Update the OAM - OAM_SUB
void updateOAM_SUB(SpriteEntry * spriteEntry)
{
   DC_FlushAll();
   dmaCopy(spriteEntry, OAM_SUB, 128 * sizeof(SpriteEntry));
}


Right, I know this is actually moving the sprites as I want, but unfortunately it seems to be resetting the sprite in the process. Looking in Dualis' OAM tells me the sprites are in the correct places, but it's basically reset the tile - blanked the sprite, the size is back to 8x8 (I assume this is the default) and whatnot. So what I'm basically looking for is something to move the sprite without affecting the rest of attributes 0 and 1, which is what this seems to be doing.

Thanks in advance for the advice and for putting up with my unfamiliarity with how the DS works (I did get quite used to the GBA though - must just be that I'm using code I'm unfamiliar with).[/code]

#108444 - Cearn - Wed Nov 08, 2006 9:41 pm

Remove the calls to the update functions from moveSprite(), they do not belong there. moveSprite() should only set the x/y fields of spriteEntry, that's all; wait with updating from the object buffer to OAM (and/or OAM_SUB) until you're done with all the work in the buffer.

The problem you have is that spriteEntry can be any one of the objects in the buffer, but updateOAM() copies 128 objects to OAM from an object array starting at its arguments address. If, say, spriteEntry is the 8th object, then you copy buffered objects 8-136 to OAM objects 0-128 and the combination of 128 copies and the offset is destroying every object in OAM.