drawBitmap always uses last set palette

I am trying to use mygame.display.drawBitmap. It works fine when drawing a single image, but when I attempt to draw 2 different images with different palettes, it used the last set palette to draw all bitmaps.

    while (mygame.isRunning())
    {
        if (mygame.update())
        {
            mygame.display.load565Palette(tile_top_pal);
            mygame.display.drawBitmap(8,8,tile_top);

			mygame.display.load565Palette(tile_body_pal);
            mygame.display.drawBitmap(8,16,tile_body);
        }
    }

In this simple example it will use ā€œtile_body_palā€ when drawing ā€œtile_topā€ even though a different palette (ā€œtile_top_palā€) was set at the time that tile_top was drawn.

Is this the expected behavior? Am I using this wrong? How can I draw multiple images with different palettes? Or is the expectation that I would have a single palette for the entire game?

Hereā€™s the graphics data:

const uint16_t tile_top_pal[] = {
0,1066,64768,43654
};

const uint8_t tile_top[] = {
8,8,
85,85,85,85,85,85,213,103,
245,175,234,191,170,255,171,254,

};

const uint16_t tile_body_pal[] = {
0,64768,43654,43654
};

const uint8_t tile_body[] = {
8,8,
90,165,106,149,170,85,169,86,
165,90,149,106,85,170,86,169,

};

In screenbuffered modes, the palette is indeed used for the entire screen.

Maybe @Hanski can chime in on how palettes are used with sprites?

2 Likes

Each sprite can have an own palette of 3 colors + a transparent color (0).

2 Likes

Both the ā€˜hiresā€™ 220x176 paletted mode and the ā€˜loresā€™ 110x88 mode have a fixed palette for the entire screen.

Currently you canā€™t mix and match palettes.

It might be possible some day, but currently there isnā€™t a screen mode that can do that.

There has been discussion of a sprite-based mode that would use one palette per sprite or a fixed number of palettes from which the sprites could choose, but as far as Iā€™m aware no work has been done on that.

2 Likes