#133384 - Phantaseur - Thu Jul 05, 2007 9:52 pm
I'm trying to display tiled background and sprite on screen at one time, but I have problems with it, I can see only sprite or only background. It depend of thing which I assign to VRAM_A. If I write
i see only sprite on the screen, if i write
i see just background. What I have to do for getting sprite and backgroung at one time?
Here is code:
Code: |
VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_SPRITE;
VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_BG; |
Code: |
VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_BG;
VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_SPRITE; |
Here is code:
Code: |
#include<nds.h>
#include<string.h> u8 redTile[64] = { 1,1,1,1,1,1,1,1, 1,2,2,2,2,2,2,1, 1,2,2,2,2,2,2,1, 1,2,2,2,2,2,2,1, 1,2,2,2,2,2,2,1, 1,2,2,2,2,2,2,1, 1,2,2,2,2,2,2,1, 1,1,1,1,1,1,1,1 }; u8 greenTile[64] = { 3,3,3,3,3,3,3,3, 3,4,4,4,4,4,4,3, 3,4,5,5,5,5,4,3, 3,4,5,5,5,5,4,3, 3,4,5,5,5,5,4,3, 3,4,5,5,5,5,4,3, 3,4,4,4,4,4,4,3, 3,3,3,3,3,3,3,3 }; int main(){ int id; SpriteEntry *spriteEntry = new SpriteEntry[128]; SpriteRotation *spriteRotation = (SpriteRotation*)spriteEntry; REG_POWERCNT=POWER_ALL_2D; DISPLAY_CR=MODE_0_2D|DISPLAY_BG0_ACTIVE|DISPLAY_SPR_ACTIVE|DISPLAY_SPR_1D; BG0_CR=BG_32x32|BG_COLOR_256|BG_MAP_BASE(0)|BG_TILE_BASE(1); /*VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_SPRITE; VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_BG;*/ VRAM_A_CR=VRAM_ENABLE|VRAM_A_MAIN_BG; VRAM_B_CR=VRAM_ENABLE|VRAM_B_MAIN_SPRITE; BG_PALETTE[1] = RGB15(31,0,0); BG_PALETTE[2] = RGB15(0,31,0); SPRITE_PALETTE[3]=RGB15(0,0,31); SPRITE_PALETTE[4]=RGB15(0,0,0); SPRITE_PALETTE[5]=RGB15(31,31,31); memcpy((void*)BG_TILE_RAM(1), redTile, 64); memcpy((void*)(BG_TILE_RAM(1)+64), greenTile, 64); for(int i=0;i<32*32;i++){ (*(unsigned short*)(void*)(BG_MAP_RAM(0)+i*2))=0; } for (int i = 0; i < 128; i++) { spriteEntry[i].attribute[0] = ATTR0_DISABLED; spriteEntry[i].attribute[1] = 0; spriteEntry[i].attribute[2] = 0; } for (int i = 0; i < 32; i++) { spriteRotation[i].hdx = 256; spriteRotation[i].hdy = 0; spriteRotation[i].vdx = 0; spriteRotation[i].vdy = 256; } id=0; spriteEntry[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE | 128; spriteEntry[0].attribute[1] = ATTR1_ROTDATA(0) | ATTR1_SIZE_8 | 96; spriteEntry[0].attribute[2] = id; for(int i=0;i<8*4;i++) SPRITE_GFX[i+id*16]=(greenTile[2*i+1]<<8)|greenTile[2*i]; DC_FlushRange(spriteEntry,128*sizeof(SpriteEntry)); dmaCopy(spriteEntry,OAM, 128*sizeof(SpriteEntry)); while(1); return(0); } |