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 > Multiple screen layers: help plz [solved]

#166494 - Pete_Lockwood - Sun Feb 08, 2009 10:00 pm

So I've got some code working which is using tiles to put stuff to a single layer and I want to extend it to use 2 layers. The code (below) is hacked from the advMultipleLayers libNds example. It *does* work for *one* layer, i.e. poking values into map[] will get the DS to draw my tiles correctly.

When I remove the comments to attempt to use a second layer, however, I'm only able to get something to draw if I poke the exact same value into map[] and map2[] at the exact same offset. I suspect this means I'm stupid and missing the plot somewhere. Can someone point me in the right direction?

Code:

void InitScreen(void)
{
   videoSetMode(MODE_5_2D);
   vramSetBankA(VRAM_A_MAIN_BG);
   
   int bg0 = bgInit(0, BgType_Text4bpp, BgSize_ER_256x256, 0,1);
//   int bg1 = bgInit(1, BgType_Text4bpp, BgSize_ER_256x256, 1,1);
   
   bgSetPriority(bg0, 0);
//   bgSetPriority(bg1, 1);
   
   // according to the sample code they magically share tiles and a palette
   dmaCopy(tilesTiles, bgGetGfxPtr(bg0), sizeof(tilesTiles));
   dmaCopy(tilesPal, BG_PALETTE, sizeof(tilesPal));

   map = (u16*)bgGetMapPtr(bg0);
//   map2 = (u16*)bgGetMapPtr(bg1);
}

_________________
It's not an illusion, it just looks like one.


Last edited by Pete_Lockwood on Thu Feb 12, 2009 1:03 am; edited 1 time in total

#166588 - dovoto - Tue Feb 10, 2009 6:51 pm

That code looks good here.

In responce to magically sharing things comment in your code:

-Backgrounds share palettes. Each tile can access one of 16 palettes and these palettes can be either 16 color or 256 color depending on how you have things set up (Text4bpp use 16 16-color palettes).

-They only share tiles because you are using the same tile graphics offset in bgInit().

Cant really tell from that code what your issue might be.
_________________
www.drunkencoders.com

#166589 - Pete_Lockwood - Tue Feb 10, 2009 7:30 pm

Thanks for replying :)

Some more info, not sure if it'll help you work out where I'm going wrong.. I set up an extra palette entry to 'highlight' certain tiles at certain points in my game:

Code:

    u16 highlight = RGB15(31,31,8);
    *(BG_PALETTE + 16 + 15) = highlight;
    *(BG_PALETTE_SUB + 16 + 15) = highlight;


When I want to highlight the tile I add 1 << 12 to the tile index to switch palette. Again, this works fine if I'm just using a single layer.

When I move to the second layer and only write tiles to map[], the only time I see anything on the screen is when I'm applying my highlight. When the tile is highlighted the tile's background takes on the highlight color but the foreground is see-through.

As I said, not sure if this helps at all.
_________________
It's not an illusion, it just looks like one.

#166590 - elhobbs - Tue Feb 10, 2009 7:50 pm

you may want to try running in an emulator like desmume and looking at the layers, palettes, tiles, and maps in the respective object viewers and make sure they are being loaded in manner you are expecting.

#166594 - Pete_Lockwood - Wed Feb 11, 2009 3:20 am

Sussed it out. It was trauma with transparency.

Thanks for the help.
_________________
It's not an illusion, it just looks like one.