Using all 4 layers in 2D mode

Post Reply
0xdbeef
Posts: 5
Joined: Wed Apr 04, 2018 10:06 pm

Using all 4 layers in 2D mode

Post by 0xdbeef » Fri May 25, 2018 2:30 pm

Hi,

I'll quickly render the problem: what I want to do is to have:

1) Console and HUD made of sprites rendered on OBJPRIORITY_0 (the most top level)
2) Tilemap background rendered on OBJPRIORITY_3 (the most bottom level)
3) Some sprites on OBJPRIORITY_1 (middle-top level)
4) Some sprites on OBJPRIORITY_2 (middle-bottom level)

For now I was just rendering all on OBJPRIORITY_0 or OBJPRIORITY_3, not using the middle layers, but let's say sprites rendered above console or in-game items like shotgun rendered under main character don't satisfy me anymore :P .

I made some changes in code, however, what my code renders after setting OBPRIORITY_1 and OBJPRIORITY_2 is:

Image

What it should render (I screenshoted using OBJPRIORITY_0 and OBJPRIORITY_3) is:

Image

Here's the code:

Initialising bg:

Code: Select all

global::bg_main_address = bgInit(OBJPRIORITY_3, BgType_Text8bpp, BgSize_B8_512x512, 22, 4);
global::bg_sub_address = bgInitSub(OBJPRIORITY_3, BgType_Text8bpp, BgSize_B8_512x512, 18, 4);
Initialising video:

Code: Select all

videoSetMode(MODE_0_2D);
videoSetModeSub(MODE_0_2D);
Initialising console:

Code: Select all

consoleInit(global::printConsole, OBJPRIORITY_0, BgType_Text4bpp, BgSize_T_256x256, map_base, tile_base, true, false);
Initialising sprites:

Code: Select all

    switch (l) {
        case (LAYER_LEVEL::BOTTOM):
            spriteEntry->priority = OBJPRIORITY_3;
            break;
        case (LAYER_LEVEL::MIDDLE_BOT):
            spriteEntry->priority = OBJPRIORITY_2;
            break;
        case (LAYER_LEVEL::MIDDLE_TOP):
            spriteEntry->priority = OBJPRIORITY_1;
            break;
        case (LAYER_LEVEL::TOP):
            spriteEntry->priority = OBJPRIORITY_0;
            break;
        default:
            spriteEntry->priority = OBJPRIORITY_0;
            break;
    }

I've found a similiar problem for mine:
https://stackoverflow.com/questions/993 ... -ds/994026

But I can't make anything out of answer: "layer 0 and 1 are normal and 2 and 3 are extended. I dont know what extended means. If you want to just do normal tile stuff you probably want to bgInit 0 and 1 not 1 and 2."
Also, I experimented a bit with different video modes and bit mappings like this one:

Code: Select all

videoSetMode(MODE_0_2D | 
                 DISPLAY_BG0_ACTIVE |
                 DISPLAY_BG1_ACTIVE | 
                 DISPLAY_BG2_ACTIVE | 
                 DISPLAY_BG3_ACTIVE); 
However, no results.

Thanks

WinterMute
Site Admin
Posts: 1385
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Using all 4 layers in 2D mode

Post by WinterMute » Sat May 26, 2018 7:42 pm

0xdbeef wrote:Hi,

Initialising bg:

Code: Select all

global::bg_main_address = bgInit(OBJPRIORITY_3, BgType_Text8bpp, BgSize_B8_512x512, 22, 4);
global::bg_sub_address = bgInitSub(OBJPRIORITY_3, BgType_Text8bpp, BgSize_B8_512x512, 18, 4);
The first parameter to bgInit(Sub) is the bg layer, not the priority. The way you have this done will mean that all background layers have the same priority (BG_PRIORITY_0) which means that they will be rendered above any sprites below OBJPRIORITY_0. It#s probably worth noting that you get an id back from bgInit(Sub) not an address.

Rendering priority is OBJPRIORITY_0 -> BG_PRIORITY_0 -> OBJPRIORITY_1 -> BG_PRIORITY_1 -> OBJPRIORITY_2 -> BG_PRIORITY_2 -> OBJPRIORITY_3 -> BG_PRIORITY_3.

You can change the background priority with bgSetPriority(id, priority).

See https://libnds.devkitpro.org/group__bac ... 4b51bc4c58
Help keep devkitPro toolchains free, Donate today

devkitPro IRC support
Personal Blog

0xdbeef
Posts: 5
Joined: Wed Apr 04, 2018 10:06 pm

Re: Using all 4 layers in 2D mode

Post by 0xdbeef » Sun May 27, 2018 5:46 am

Thanks!

This code placed under bgInit / bgInitSub fixed the problem:

Code: Select all

    
bgSetPriority(global::bg_main_address, BG_PRIORITY_3);
bgSetPriority(global::bg_sub_address, BG_PRIORITY_3);

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests