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.

Coding > I need help with my function

#7429 - mandarin - Tue Jun 17, 2003 7:54 pm

Hi all,

I have for the last 2 weeks been busy with my RPG and i came up with this spritedisplay function for my items, but i can't seem to display both sprites on the screen at the same time. Can anyone help?

Heres the code :

u16* OAM = (u16*)0x7000000;

OAMEntry sprites[128];
pRotData rotData = (pRotData)sprites;

void WaitForVsync()
{
while((volatile u16)REG_VCOUNT != 160){}
}

void CopyOAM()
{
u16 loop;
u16* temp;
temp = (u16*)sprites;
for(loop = 0; loop < 128*4; loop++)
{
OAM[loop] = temp[loop];
}
}

void initsprites()
{
u16 loop;

for(loop=0;loop<128;loop++)
{
sprites[loop].attribute0 = 160;
sprites[loop].attribute1 = 240;
}
}

int displayitems(u16 x, u16 y, int no)

{
u16 loop;
u16 num;
u16 attrnum;

attrnum=0;
attrnum=no*8;
num=0;
num=no;




for(loop=0; loop < 128 ; loop++) {
OBJPaletteMem[loop] = itemsPalette[loop];
}
initsprites();

sprites[no].attribute0 = COLOR_256 | SQUARE | y;
sprites[no].attribute1 = SIZE_16 | x;
sprites[no].attribute2 = attrnum;

if (no = 0) {

num=num+128;

for(loop = 0; loop < 128;loop++)
{
OAMData[loop] = itemsData[loop];
}
}
else {
num=(num+1)*128;
for(loop = 128; loop <num;loop++)
{
OAMData[loop] = itemsData[loop-128];
}
}

}


int main()
{
setmode(mode1 | objmap1d | objenable);


displayitems(40,50,1);

displayitems(60,100,2);

while (1) {

WaitForVsync();
CopyOAM();
}
}

#7432 - Cyberman - Tue Jun 17, 2003 9:17 pm

You are using mode 1
This is 2 BG and 1 Rotatable
I would check to see if both sprites have there priority set higher than either of the back grounds first. Also see if they are in the right order. IE if Obj B should be visable about Obj A then B should have a lower Sprite offset into the OAM (lower means higher priority).

Cyb

#7435 - mandarin - Tue Jun 17, 2003 9:52 pm

thanx man , but just one thing how do i change the sprites priority give me a sample code if u can plz.

#7565 - Arek the Absolute - Thu Jun 19, 2003 9:23 pm

You should also check to make sure you're not overwriting your sprite image data. It looks to me like every time you copy image data into the EXACT same place in OAM, which means you can't show more than one at a time. In order to show multiple sprites you're going to need to make sure that you put the image data for each sprite in a position that corresponds with that sprite's character number.
_________________
-Arek the Absolute

#7810 - jcpredator - Wed Jun 25, 2003 1:59 pm

I agree with Arek, to me it looks like your overwriting ur sprite data.
_________________
There is no spoon...