Search code examples
csonic

doesn't load image palette in PAL0 -> VDP_setPalette(PAL0,sprite_sonic.palette->data)


Decided to look into the SGDK. I wanted to add a Sonic's sprite to the screen, but something went wrong. Sonic's sprite loads but not in his palette. When loading, the PAL0 palette is used, in which the default colors remain (although I kind of changed them). Here is a photo with a problem -> sonic. This photo shows that Sonic is Black and White, and that PAL0 has not changed. Here is the code:

#include <genesis.h>
#include "sprites.h"

Sprite* my_sprite_sonic;

int main()
{
    VDP_setBackgroundColor(40);
    VDP_setScreenWidth320();

    SPR_init();

    VDP_setPalette(PAL0,sprite_sonic.palette->data);
    
    my_sprite_sonic = SPR_addSprite(&sprite_sonic, 0, 0, TILE_ATTR(PAL0, TRUE, FALSE, FALSE));

    while(TRUE)
    {
        SPR_update();
        SYS_doVBlankProcess();
    }

    return 0;
}

If I'm being stupid, I apologize in advance. New to SGDK. I googled the question but couldn't find anything.


Solution

  • Instead of VDP_setPalette(PAL0,sprite_sonic.palette->data); you need to use PAL_setPalette(PAL0, sonic_sprite.palette->data, DMA);