#170160 - headspin - Fri Sep 04, 2009 7:37 pm
I got sprites on both screens working in a game previously but this is my first time using the latest libnds so I am trying to use the helper functions as much as possible.
Anyway I can't seem to get sprites to display on both screens using libnds and the bank layout I'm currently using. I decided to open up the bitmap_sprites demo and add display to the secondary screen. This works fine.
The problem is when I change the graphics layout to add support for bg tiles the sprites don't appear on the main screen.
ie.
When I change the bank layout to the following I get sprites displaying on both screens again but in my game my main screen disappears (I get the sprite on both screens but none of the backgrounds appear on main screen!).
So my question is why can't I get sprites displaying on both screens using the following memory layout:
I thought that perhaps it was an issue caused by using bitmap sprites but I changed them all to 256 color sprites and still the same issue.
Here is my video setup code:
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
Anyway I can't seem to get sprites to display on both screens using libnds and the bank layout I'm currently using. I decided to open up the bitmap_sprites demo and add display to the secondary screen. This works fine.
Code: |
#include <nds.h>
#include <stdio.h> //a simple sprite structure //it is generally preferred to separate your game object //from OAM typedef struct { u16* gfx; SpriteSize size; SpriteColorFormat format; int rotationIndex; int paletteAlpha; int x; int y; } MySprite; int main(int argc, char** argv) { //three sprites of differing color format MySprite spritesMain[] = { {0, SpriteSize_32x32, SpriteColorFormat_Bmp, 0, 15, 20, 15}, {0, SpriteSize_32x32, SpriteColorFormat_256Color, -1, 0, 20, 80}, {0, SpriteSize_32x32, SpriteColorFormat_16Color, -1, 1, 20, 136} }; MySprite spritesSub[] = { {0, SpriteSize_32x32, SpriteColorFormat_Bmp, 0, 15, 20, 15}, {0, SpriteSize_32x32, SpriteColorFormat_256Color, -1, 0, 20, 80}, {0, SpriteSize_32x32, SpriteColorFormat_16Color, -1, 1, 20, 136} }; videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); consoleDemoInit(); //initialize the sub sprite engine with 1D mapping 128 byte boundary //and no external palette support oamInit(&oamMain, SpriteMapping_Bmp_1D_128, false); oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false); vramSetBankA(VRAM_A_MAIN_SPRITE); vramSetBankD(VRAM_D_SUB_SPRITE); //allocate some space for the sprite graphics for(int i = 0; i < 3; i++) { spritesMain[i].gfx = oamAllocateGfx(&oamMain, spritesMain[i].size, spritesMain[i].format); spritesSub[i].gfx = oamAllocateGfx(&oamSub, spritesSub[i].size, spritesSub[i].format); } //ugly positional printf iprintf("\x1b[1;1HDirect Bitmap:"); iprintf("\x1b[9;1H256 color:"); iprintf("\x1b[16;1H16 color:"); //fill bmp sprite with the color red dmaFillHalfWords(ARGB16(1,31,0,0), spritesMain[0].gfx, 32*32*2); dmaFillHalfWords(ARGB16(1,31,0,0), spritesSub[0].gfx, 32*32*2); //fill the 256 color sprite with index 1 (2 pixels at a time) dmaFillHalfWords((1<<8)|1, spritesMain[1].gfx, 32*32); dmaFillHalfWords((1<<8)|1, spritesSub[1].gfx, 32*32); //fill the 16 color sprite with index 1 (4 pixels at a time) dmaFillHalfWords((1<<12)|(1<<8)|(1<<4)|1, spritesMain[2].gfx, 32*32 / 2); dmaFillHalfWords((1<<12)|(1<<8)|(1<<4)|1, spritesSub[2].gfx, 32*32 / 2); //set index 1 to blue...this will be the 256 color sprite SPRITE_PALETTE[1] = RGB15(0,31,0); //set index 17 to green...this will be the 16 color sprite SPRITE_PALETTE[16 + 1] = RGB15(0,0,31); //set index 1 to blue...this will be the 256 color sprite SPRITE_PALETTE_SUB[1] = RGB15(0,31,0); //set index 17 to green...this will be the 16 color sprite SPRITE_PALETTE_SUB[16 + 1] = RGB15(0,0,31); int angle = 0; while(1) { for(int i = 0; i < 3; i++) { oamSet( &oamMain, //sub display i, //oam entry to set spritesMain[i].x, spritesMain[i].y, //position 0, //priority spritesMain[i].paletteAlpha, //palette for 16 color sprite or alpha for bmp sprite spritesMain[i].size, spritesMain[i].format, spritesMain[i].gfx, spritesMain[i].rotationIndex, true, //double the size of rotated sprites false, //don't hide the sprite false, false, //vflip, hflip false //apply mosaic ); oamSet( &oamSub, //sub display i, //oam entry to set spritesSub[i].x, spritesSub[i].y, //position 0, //priority spritesSub[i].paletteAlpha, //palette for 16 color sprite or alpha for bmp sprite spritesSub[i].size, spritesSub[i].format, spritesSub[i].gfx, spritesSub[i].rotationIndex, true, //double the size of rotated sprites false, //don't hide the sprite false, false, //vflip, hflip false //apply mosaic ); } oamRotateScale(&oamMain, 0, angle, (1 << 8), (1<<8)); oamRotateScale(&oamSub, 0, angle, (1 << 8), (1<<8)); angle += 64; swiWaitForVBlank(); //send the updates to the hardware oamUpdate(&oamMain); oamUpdate(&oamSub); } return 0; } |
The problem is when I change the graphics layout to add support for bg tiles the sprites don't appear on the main screen.
ie.
Code: |
vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE); |
When I change the bank layout to the following I get sprites displaying on both screens again but in my game my main screen disappears (I get the sprite on both screens but none of the backgrounds appear on main screen!).
Code: |
vramSetMainBanks(VRAM_A_MAIN_SPRITE, VRAM_B_MAIN_BG, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE); |
So my question is why can't I get sprites displaying on both screens using the following memory layout:
Code: |
vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE); |
I thought that perhaps it was an issue caused by using bitmap sprites but I changed them all to 256 color sprites and still the same issue.
Here is my video setup code:
Code: |
#define BG0_MAP_BASE 26
#define BG0_MAP_BASE_SUB 26 #define BG1_MAP_BASE 27 #define BG1_MAP_BASE_SUB 27 #define BG2_MAP_BASE 28 #define BG2_MAP_BASE_SUB 28 #define BG3_MAP_BASE 30 #define BG3_MAP_BASE_SUB 30 #define BG0_TILE_BASE 7 #define BG0_TILE_BASE_SUB 7 #define BG1_TILE_BASE 5 #define BG1_TILE_BASE_SUB 5 #define BG2_TILE_BASE 6 #define BG2_TILE_BASE_SUB 6 #define BG3_TILE_BASE 0 #define BG3_TILE_BASE_SUB 0 videoSetMode(MODE_0_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE); videoSetModeSub(MODE_0_2D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE); vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE); bgInit(0, BgType_Text4bpp, BgSize_T_256x256, BG0_MAP_BASE, BG0_TILE_BASE); bgInit(1, BgType_Text8bpp, BgSize_T_256x256, BG1_MAP_BASE, BG1_TILE_BASE); bgInit(2, BgType_Text8bpp, BgSize_T_256x256, BG2_MAP_BASE, BG2_TILE_BASE); bgInit(3, BgType_Text8bpp, BgSize_T_256x256, BG3_MAP_BASE, BG3_TILE_BASE); bgInitSub(1, BgType_Text8bpp, BgSize_T_256x256, BG1_MAP_BASE_SUB, BG1_TILE_BASE_SUB); int bg2Sub = bgInitSub(2, BgType_Text8bpp, BgSize_T_512x256, BG2_MAP_BASE_SUB, BG2_TILE_BASE_SUB); int bg3Sub = bgInitSub(3, BgType_Text8bpp, BgSize_T_512x256, BG3_MAP_BASE_SUB, BG3_TILE_BASE_SUB); bgSetControlBits(bg2Sub, BG_PRIORITY_0); bgSetControlBits(bg3Sub, BG_PRIORITY_2); lcdMainOnBottom(); // Some dma'ing of tiles and stuff here oamInit(&oamMain, SpriteMapping_Bmp_1D_128, false); oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false); |
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game