#85059 - PacoChan - Fri May 26, 2006 9:09 pm
Hi, sorry for my english, but I'm spanish. I have a problem drawing sprites. I draw a bitmap 32*32 in SPRITE_GFX with this:
And it works fine.
But when I draw the same bitmap or another one on another position of SPRITE_GFX, it doesn't appear correctly:
Here is all the code:
I'm a noob working with sprites, so try to explain me how to solve this issue in a way that a noob can understand. Thanks.[/code]
Code: |
for(i=0;i<32*32;i++) SPRITE_GFX[i]=((u16*)enemigo_bin)[i] | (1<<15); |
And it works fine.
But when I draw the same bitmap or another one on another position of SPRITE_GFX, it doesn't appear correctly:
Code: |
for(i=32*32;i<32*32*2;i++) PRITE_GFX[i]=((u16*)enemigo_bin)[i] | (1<<15); |
Here is all the code:
Code: |
#include <nds.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <nds/arm9/console.h> //basic print funcionality #include "enemigo_bin.h" SpriteEntry sprites[128]; //turn off all the sprites void initSprites(void) { int i; for(i = 0; i < 128; i++) { sprites[i].attribute[0] = ATTR0_DISABLED; sprites[i].attribute[1] = 0; sprites[i].attribute[2] = 0; sprites[i].attribute[3] = 0; } } //copy our sprite to object attribute memory void updateOAM(void) { DC_FlushAll(); dmaCopy(sprites, OAM, 128 * sizeof(SpriteEntry)); } //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- powerON(POWER_ALL_2D); //irqs are nice irqInit(); irqSet(IRQ_VBLANK, 0); touchPosition touchXY; //enable vram and map it to the right places vramSetMainBanks( VRAM_A_MAIN_SPRITE, //A and B maped consecutivly as sprite memory VRAM_B_MAIN_SPRITE, //this gives us 256KB which is the max VRAM_C_SUB_BG, //map C to background memory VRAM_D_MAIN_BG_0x6000000 //not using D ); //set the video mode videoSetMode( MODE_0_2D | DISPLAY_SPR_ACTIVE | //turn on sprites DISPLAY_BG0_ACTIVE | //turn on background 0 DISPLAY_SPR_1D | //this is used when in tile mode DISPLAY_SPR_1D_BMP //and this in bitmap mode ); BG_PALETTE[0]=RGB15(0,0,0); videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); //sub bg 0 will be used to print text SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[0] = RGB15(31,15,0); //by default font will be rendered with color 255 BG_PALETTE_SUB[255] = RGB15(31,31,0); //by default font will be rendered with color 255 //consoleInit() is a lot more flexible but this gets you up and running quick consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16); initSprites(); int i; for(i=0;i<32*32;i++) SPRITE_GFX[i]=((u16*)enemigo_bin)[i] | (1<<15); for(i=32*32;i<32*32*2;i++) SPRITE_GFX[i]=((u16*)enemigo_bin)[i] | (1<<15); sprites[0].attribute[0] = ATTR0_BMP | 0; sprites[0].attribute[1] = ATTR1_SIZE_32 | 0; sprites[0].attribute[2] = ATTR2_ALPHA(1) | 0; sprites[1].attribute[0] = ATTR0_BMP | 0; sprites[1].attribute[1] = ATTR1_SIZE_32 | 32; sprites[1].attribute[2] = ATTR2_ALPHA(1)| 16; int x=0, y=0; lcdSwap(); while(1) { scanKeys(); touchXY=touchReadXY(); iprintf("\x1b[10;0HTouch x = %04X, %04X\n", touchXY.x, touchXY.px); iprintf("Touch y = %04X, %04X\n", touchXY.y, touchXY.py); if(keysHeld() & KEY_RIGHT) x++; if(keysHeld() & KEY_LEFT) x--; if(keysHeld() & KEY_UP) y--; if(keysHeld() & KEY_DOWN) y++; swiWaitForVBlank(); updateOAM(); } return 0; } |
I'm a noob working with sprites, so try to explain me how to solve this issue in a way that a noob can understand. Thanks.[/code]