• Advertisement

Archived

This topic is now archived and is closed to further replies.

Sprites not appearing

This topic is 5062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

EDIT: My last post has more up to date information on the problem at hand, if you wouldn't mind scrolling down. Thank you. I'm working on getting sprites to work in my gba application. It compiles but the sprites just don't appear. Quite odd. Relavent (but not exhaustive) code snippet:

u16* videoBuffeer = ((u16*)0x6000000);
u16* paletteMem = ((u16*)0x5000000);
u16* OAM = ((u16*)0x7000000);

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

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

void initializeSprites()
{
	for(u16 i = 0; i < 128; i++)
	{
		sprites[i].attribute0 = 160;
		sprites[i].attribute1 = 240;
	}
    
}

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

int main()
{
	s16 x = 100, y = 60;

	setMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

	for(int i = 0; i < 256; i++)
		OBJPaletteMem[i] = mySpritePalette[i];

	initializeSprites();

	sprites[0].attribute0 = COLOR_256 | SQUARE | x;
	sprites[0].attribute1 = SIZE_64 | y;
	sprites[0].attribute2 = 0;

	for(int i = 0; i < 128; i++)
		OAMdata[i] = mySpriteData[i];

	setMode(MODE_4 | BG2_ENABLE);

	for(int i = 0; i < 256; i++)
		paletteMem[i] = FFPalette[i];

	for(int i = 0; i < 120; i++)
		for(int j = 0; j < 160; j++)
			plotPixel(i, j, FFData[j * 120 + i]);


	while(1)
	{
		VSync();
		copyOAM();
        
	}

	return 0;
}

The background scene (FF) draws but the sprites don't. I don't think they're being overlapped because I only added the background image later to make sure that the sprite wasn't just blending in with the black background (it's in black and white). Any thoughts? I'm fresh out. EDIT: Provided additional info When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon... [edited by - CyberSlag5k on April 16, 2004 5:51:25 PM] [edited by - CyberSlag5k on April 17, 2004 1:46:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
Hmm....well, as I said I''ve tried just drawing the sprite with no background. Plus, the background should have lower priority than the sprite. An interesting thing to note, however, if I put the background image stuff first and run the program, the background image appears for a second and then the screen goes all white. Could I somehow be drawing the sprite really big? It is partially white.

Any help would be appreciated.

When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites
Alright, still not getting the stupid sprite loaded, but here's an update. I've taken out the background image stuff for now just to simplify things. When I run my program in mappyVM and go into the sprite viewer, sprite[0] appears to have all the correct settings, but the preview picture is all black. This leads me to think I am somehow incorrectly loading my sprite in OAM.

Now, please take a look here. The first set of code is mine, the second is one of gbajunkie's tutorials that I've modeled my own after.


u16* videoBuffeer = ((u16*)0x6000000);
u16* paletteMem = ((u16*)0x5000000);
u16* OAM = ((u16*)0x7000000);

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

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

void initializeSprites()
{
for(u16 i = 0; i < 128; i++)
{
sprites[i].attribute0 = 160;
sprites[i].attribute1 = 240;
}

}

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


void plotPixel(int x, int y, unsigned short int c)
{
videoBuffeer[(y) * 120 + (x)] = (c);
}

void setMode(u16 mode)
{
REG_DISPCNT = mode;
}

int main()
{


s16 x = 100, y = 60;

setMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

for(int i = 0; i < 256; i++)
OBJPaletteMem[i] = mySpritePalette[i];

initializeSprites();

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

for(int i = 512; i < 640; i++)
OAMdata[i] = mySpriteData[i];


while(1)
{
VSync();
copyOAM();

}




return 0;
}





//create an OAM variable and make it point to the address of OAM

u16* OAM = (u16*)0x7000000;

//create the array of sprites (128 is the maximum)

OAMEntry sprites[128];

//create the rotation and scaling array (overlaps the OAMEntry array memory)

pRotData rotData = (pRotData)sprites;

//Copy our sprite array to OAM

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

//Set sprites to off screen

void InitializeSprites()
{
u16 loop;
for(loop = 0; loop < 128; loop++)
{
sprites[loop].attribute0 = 160; //y to > 159

sprites[loop].attribute1 = 240; //x to > 239

}
}

//wait for the screen to stop drawing

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


int main()
{
u16 loop;
s16 x = 100;
s16 y = 60;

SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

for(loop = 0; loop < 256; loop++)
OBJPaletteMem[loop] = pacspritePalette[loop];

InitializeSprites();

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

for(loop = 0; loop < 128; loop++)
{
OAMData[loop] = pacspriteData[loop];
}

while(1)
{
WaitForVsync();
CopyOAM();
}
}


Now, someone please either re-affirm to me that my code matches gbajunkie's so I know that I'm not going crazy, or point out the flaw in mine so I can fix this stupid thing and go to bed.

Thank you



When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

[edited by - CyberSlag5k on April 17, 2004 1:47:43 AM]

Share this post


Link to post
Share on other sites
The Differences:

Difference A: you''ve swapped X and Y...

/* GBAJunkie''s: */
sprites[0].attribute0 = COLOR_256 | SQUARE | y;
sprites[0].attribute1 = SIZE_16 | x;
sprites[0].attribute2 = 0;

/* Yours: */
sprites[0].attribute0 = COLOR_256 | SQUARE | x;
sprites[0].attribute1 = SIZE_16 | y;
sprites[0].attribute2 = 0;


Difference B: you''ve got some really messed-up array indices...

/* GBAJunkie''s: */
for(loop = 0; loop < 128; loop++)
{
OAMData[loop] = pacspriteData[loop];
}

/* Yours: */
for(int i = 512; i < 640; i++)
OAMdata[i] = mySpriteData[i];


Hope this helps!

Share this post


Link to post
Share on other sites
quote:

Difference B: you''ve got some really messed-up array indices...



Oh, heh, I forgot about that. That was just something I tried out of desparation.

And yeah, good call on the x and y. I never noticed that before.

Thank you.

When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites
Allllright, problem solved.

I use two different websites to learn gba development from, gbajunkie.co.uk and thepernproject.com. Both are tremendous sites and I highly recommend them both. However, as it turns out I was using the gba.h file from thepernproject with code based off gbajunkie''s tutorial and for some reason it wasn''t showing the sprites. So I replaced the pern gba.h with the gbajunkie gba.h and now it shows up. It''s smaller than it should be, but I''m currently investigating that right now (I have a feeling my pcx2sprite program is at fault).

Thank you to everyone who helped!

When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites
And yet another update, just in case anyone runs into a similar problem down the line. The reason only part of my sprite was showing was because I was loading my sprite like this:


for(int i = 0; i < 256; i++)
OBJPaletteMem[i] = mySpritePalette[i];

initializeSprites();

sprites[0].attribute0 = COLOR_256 | SQUARE | y;
sprites[0].attribute1 = SIZE_64 | x;
sprites[0].attribute2 = 0;

for(int i = 0; i < 128; i++)
OAMData[i] = mySpriteData[i];



Now, you''ll notice I st my size in attribute 1 to 64. The tutorial I was working off of only set theirs to 16. I changed mine''s size but did not change the loop that loaded my sprite''s data into OAM accordingly. You''ll note that the way I do it there loads the first 128 pixels. I would only need to load 128 pixels if I were only making a 16*16 square since the GBA draws 2 pixels for each one in the horizontal (16*16/2 = 128). However I am making a 64*64 square and hence needed to load 2048 (64*64/2 = 2048). So in essence, I was only loading 1/16 of my sprite into OAM.

Hope this helps someone down the line!

When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites

  • Advertisement