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 > Help with sprites

#16146 - Darmstadium - Mon Feb 09, 2004 10:58 pm

I am having a lot of trouble making my own sprites and making them appear. I'm using dovoto's pcx2sprite program to make a header file with an array with my sprite. When I compile my code, there is nothing at all resembling my image. Here's my code:
Code:

#include "gba.h"
#include "dispcnt.h"
#include "spriteMan.h"
#include "keypad.h"
#include "sprite.h"

u16* OAM = (u16*)0x7000000;
OAMEntry sprites[128];
pRotData rotData = (pRotData)sprites;
u16 loop;

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

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

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

int main()
{
   SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);
   for(loop = 0; loop < 256; loop++)
      OBJPaletteMem[loop] = spriteManPalette[loop];
   InitializeSprites();
   sprites[0].attribute0 = COLOR_256 | TALL | 60;
   sprites[0].attribute1 = SIZE_32 | 60;
   sprites[0].attribute2 = 0;
   for(loop = 0; loop < 256; loop++)
      OAMData[loop] = spriteManData[loop];
   while(1)
   {
      WaitForVsync();
      CopyOAM();
   }
   return 0;
}

Any help anyone could give would be GREATLY appreciated.

#16149 - yaustar - Mon Feb 09, 2004 11:10 pm

can you post spriteMen.h? It may have a problem with the conversion of data. Try gif2sprite

edit:
Code:
for(loop = 0; loop < 256; loop++)
      OAMData[loop] = spriteManData[loop];

This seems a bit low for a 32x32 sprite, I would have thought it be 1024
_________________
[Blog] [Portfolio]

#16152 - Darmstadium - Mon Feb 09, 2004 11:32 pm

Code:

const u16 spriteManData[] = {
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFC00, 0x0000, 0x0000, 0x0000, 0xDD00,
                    0x0000, 0x0000, 0x0000, 0x0300, 0x0000, 0x0000, 0xFC00, 0xFCFC, 0x0000, 0x0000,
                    0xDD00, 0xDDDD, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x00FC, 0x0000, 0x0000, 0x0000, 0x00DD, 0x0000,
                    0x0000, 0x0000, 0x0003, 0x0000, 0x0000, 0x0000, 0xFCFC, 0x00FC, 0x0000, 0x0000,
                    0xDDDD, 0x00DD, 0x0000, 0x0000, 0x0000, 0x0000, 0x0300, 0x0303, 0x0000, 0x0000,
                    0xFCFC, 0xFBFC, 0x0000, 0x0000, 0xDDDD, 0xE9DD, 0x0000, 0x0000, 0x0303, 0xC603,
                    0x0000, 0x0000, 0xFCFC, 0xFBFB, 0x0000, 0x0000, 0xDDDD, 0xE9E9, 0x0000, 0x0000,
                    0x0303, 0xC6C6, 0x0000, 0x0000, 0xFBFC, 0xFB33, 0x0303, 0x0003, 0x0000, 0x0000,
                    0xFCFB, 0xFCFC, 0x0000, 0x0000, 0xDDE9, 0xDDDD, 0x0000, 0x0000, 0x03C6, 0x0303,
                    0x0000, 0x0000, 0xF7FB, 0xFCFC, 0x0000, 0x0000, 0xC0E9, 0xDDDD, 0x0000, 0x0000,
                    0x5BC6, 0x0303, 0x0000, 0x0000, 0x33FB, 0xFCF7, 0x0000, 0x0000, 0x0000, 0x0000,
                    0xE9DD, 0xE933, 0x0000, 0x0000, 0xC603, 0xC633, 0x0000, 0x0000, 0xFB00, 0xFBFB,
                    0x0000, 0x0000, 0xE900, 0xE9E9, 0x0000, 0x0000, 0xC600, 0xC6C6, 0x0000, 0x0000,
                    0xFB00, 0xFB33, 0x0000, 0x0000, 0xE900, 0xE933, 0x0000, 0x0000, 0xC600, 0xC633,
                    0x33E9, 0xDDC0, 0x0000, 0x0000, 0x33C6, 0x035B, 0x0000, 0x0000, 0xF7FB, 0x00F7,
                    0x0000, 0x0000, 0xC7E9, 0x00C7, 0x0000, 0x0000, 0x6FC6, 0x006F, 0x0000, 0x0000,
                    0x33F7, 0x00F7, 0x0000, 0x0000, 0x33C7, 0x00C0, 0x0000, 0x0000, 0x336F, 0x005B,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x33FB, 0x0000, 0x0000, 0x0000, 0x33E9,
                    0x0000, 0x0000, 0x0000, 0x33C6, 0x0000, 0x0000, 0x0000, 0xF700, 0x0000, 0x0000,
                    0x0000, 0xC700, 0x0000, 0x0000, 0x0000, 0x6F00, 0x0000, 0x0000, 0x8000, 0x8080,
                    0x0000, 0x0000, 0x0000, 0x0000, 0xF733, 0x0000, 0x0000, 0x0000, 0xC033, 0x0000,
                    0x0000, 0x0000, 0x5B33, 0x0000, 0x0000, 0x0000, 0x00F7, 0x0000, 0x0000, 0x0000,
                    0x00C0, 0x0000, 0x0000, 0x0000, 0x005B, 0x0000, 0x0000, 0x0000, 0x8080, 0x0080,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};

const u16 spriteManPalette[] = {
                    0x0802, 0x0802, 0x0802, 0x0802, 0x0802, 0x0802, 0x0802, 0x0802, 0x0802, 0x0000,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
                    0x0800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
                    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0800, 0x0000, 0x0000, 0x0000,
                    0x0000, 0x0004, 0x0000, 0x0421, 0x0421, 0x0842, 0x0842, 0x0C63, 0x0C63, 0x1084,
                    0x1084, 0x14A5, 0x14A5, 0x18C6, 0x18C6, 0x1CE7, 0x1CE7, 0x2108, 0x2108, 0x2529,
                    0x2529, 0x294A, 0x294A, 0x2D6B, 0x2D6B, 0x210C, 0x2108, 0x2529, 0x2529, 0x294A,
                    0x294A, 0x2D6B, 0x3DEF, 0x4210, 0x4210, 0x4631, 0x4631, 0x4A52, 0x4A52, 0x4673,
                    0x4671, 0x5294, 0x5294, 0x56B5, 0x56B5, 0x5AD6, 0x5AD6, 0x5EF7, 0x5EF7, 0x6318,
                    0x6318, 0x6739, 0x6739, 0x6B5A, 0x6B5A, 0x6F7B, 0x6F7B, 0x6318, 0x6318, 0x6739,
                    0x6739, 0x6B5A, 0x6B5A, 0x6F7B, 0x6F7B, 0x0004, 0x0000, 0x0421, 0x0421, 0x0842,
                    0x0842, 0x0C63, 0x0C63, 0x1084, 0x1084, 0x14A5, 0x14A5, 0x18C6, 0x18C6, 0x1CE7,
                    0x1CE7, 0x3188, 0x318C, 0x35AD, 0x35AD, 0x39CE, 0x39CE, 0x3DEF, 0x2D6B, 0x318C,
                    0x318C, 0x35AD, 0x35AD, 0x39CE, 0x39CE, 0x3DEF, 0x3DEF, 0x4210, 0x4210, 0x4E31,
                    0x4E33, 0x4A52, 0x4A52, 0x4E73, 0x4E73, 0x5294, 0x5294, 0x56B5, 0x56B5, 0x5AD6,
                    0x5AD6, 0x5EF7, 0x5EF7, 0x739C, 0x739C, 0x77BD, 0x77BD, 0x7BDE, 0x7BDE, 0x7FFF,
                    0x7FFF, 0x739C, 0x739C, 0x77BD, 0x77BD, 0x7BDE, 0x7BDE, 0x7FFF, 0x7FFF, 0x0004,
                    0x0000, 0x0421, 0x0421, 0x0842, 0x0842, 0x0C63, 0x0C63, 0x1084, 0x1084, 0x14A5,
                    0x14A5, 0x18C6, 0x18C6, 0x1CE7, 0x1CE7, 0x2108, 0x2108, 0x2529, 0x2529, 0x294A,
                    0x294A, 0x2D6B, 0x2D6B, 0x318C, 0x318C, 0x35AD, 0x35AD, 0x39CE, 0x39CE, 0x3DEF,
                    0x3DEF, 0x4210, 0x4210, 0x4631, 0x4631, 0x4A52, 0x4A52, 0x4E73, 0x4E73, 0x5294,
                    0x5294, 0x33F1, 0x0015, 0x0020, 0x3809, 0x7A92, 0x3000, 0x382A, 0x0015, 0x0000,
                    0x3001, 0x3000, 0x3809, 0x0008, 0x0000, 0x000A, 0x000A, 0x33F6, 0x7A88, 0x3000,
                    0x7A8B, 0x3000, 0x0008, 0x0000, 0x0020, 0x0020, 0x3839, 0x33F8, 0x7E33, 0x3000,
                    0x0020, 0x0008, 0x33E7, 0x2122, 0x3000, 0x0001, 0x0020, 0x0000, 0x0002, 0x2800,
                    0x20DA, 0x0000, 0x0000, 0x3675, 0x2072, 0x21C0,};


My sprite is actualy 16x32

#16159 - yaustar - Tue Feb 10, 2004 12:24 am

Code:
sprites[0].attribute1 = SIZE_32 | 60;

This bit of code tells the GBA that is is 32x32. I am not sure on this but you may need to declare as WIDE or TALL. I havent had any experience on this, your best bet is to search the forums or read the GBA Trek or Cowbite specs.
_________________
[Blog] [Portfolio]

#16160 - yaustar - Tue Feb 10, 2004 12:37 am

I just saw that you have declared it TALL :p

umm.... try declaring it as wide, I remember vaguely that they were the wrong way round?
_________________
[Blog] [Portfolio]

#16162 - sajiimori - Tue Feb 10, 2004 12:42 am

At first glance, your code seems fine (but get rid of that global loop variable cuz it keeps the optimizer from doing its job). Use VBA to check the OAM, sprite data, and palette to make sure they are what you expect.

#16167 - Darmstadium - Tue Feb 10, 2004 1:46 am

I checked the memory. The palette is ok, but the OAM is definately wrong, that is it doesn't match what's in the array that stores the sprite. Have any idea of what the cause of this might be?

#16175 - DekuTree64 - Tue Feb 10, 2004 4:11 am

Please don't post the same thing in every section.
Most people here read all the sections anyway, they're just to help keep things organized better.
If anything, multi-posting will just make people mad, not give you a better chance of finding help.

That said, is it the sprite image data in the tile viewer window (check the data at 0x6010000) the thing that's messed up, or the sprite in the OAM viewer (OAM is the sprite position/size-type data)? The code looks ok, so I can't really track the problem.
Is OAMData defined as ((u16*)0x6010000)? If not, either change it to that, or you'll have to cast to a u16* since the sprite data is a u16 array. Other than that I can't think of anything right off the bat.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#16224 - Darmstadium - Tue Feb 10, 2004 10:40 pm

OAMData is equal to (u16*)0x6010000.

#16226 - johnny_north - Tue Feb 10, 2004 11:23 pm

Gosh, I feel bad for someone when you have a problem that no one can seem to help with. I don't know enough here to make a good suggestion, but here goes anyway-

Your palette values seem suspect to me, judging from the first nine entries being the same, the next twenty being the same, etc. Again, you may have set something up to make it this way, but it caught my attention.

Have you had success with this conversion tool before? If not, I can recommend gfx2gba v1.13.

I did load up your sprite and palette data into an exising project of mine. Nothing about those tiles looks like a "man" to me, so I suspect the conversion process is failing in some way.

-Jon

#16228 - Darmstadium - Wed Feb 11, 2004 12:27 am

Thanks a lot for your help everyone. I tried gfx2gba by darren and my sprite shows up! HOORAY!

#16229 - yaustar - Wed Feb 11, 2004 12:29 am

It was his palette issues. He was trying to convert a 16 million colour pxc file and the tool doesnt support it.

edit: too late again :(
_________________
[Blog] [Portfolio]