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 > 16 bits sprite

#138866 - ghuldan - Thu Aug 30, 2007 1:05 am

hi

What's the format of 16 bits sprite colors ?

I try to convert my 256 colors palette sprite to 16 bits sprite using the same ressources (i.e indexed gfx with a palette), but when i try to fill my gfx with my old color palette, it does not seem to work (sprite is transparent).
But if i fill it with a color i pick from PAGfx it works.

by now i use this to create a color :
#define RGB(r, g, b) ( ( (b) << 10 ) + ( (g) << 5 ) + (r) )
ex : color = RGB(31,31,31); (for white color)

Code:
unsigned short *gfx = malloc(sizeof(unsigned short) * 32 * 32);
for (i = 0; i < 32 * 32; i++)
   gfx[i] = RGB(31,31,31);
PA_Create16bitSprite (..., ..., (void*)gfx, OBJ_SIZE_32X32, ..., ...);

it does not work

Code:
unsigned short *gfx = malloc(sizeof(unsigned short) * 32 * 32);
for (i = 0; i < 32 * 32; i++)
   gfx[i] = 33791; /*picked from a 16 bits sprite created by PAGfx*/
PA_Create16bitSprite (..., ..., (void*)gfx, OBJ_SIZE_32X32, ..., ...);

it does work

Can someone help plz ?

#138868 - Cydrak - Thu Aug 30, 2007 1:32 am

Code:
gfx[i] = 33791;   // 0x83ff

Notice the high bit.. 16 bit objects use it for transparency (whereas the palettes use index 0, ignoring it). So try something like:

Code:
#define ALPHA_BIT 0x8000

for(each u16 spritePixel, u8 srcPixel) {
    if(srcPixel != 0) spritePixel = ALPHA_BIT | srcPalette[srcPixel];
    else              spritePixel = 0;
}

#138890 - ghuldan - Thu Aug 30, 2007 8:27 am

yooohoo ! thanks ^^