#55856 - chrissieboy - Mon Oct 03, 2005 2:57 pm
Hi, im just started again with ds development.
Everything seems to been changed a littlebit.
Im now trying to make a puzzle game with sprites, but 3 months before it was realy easy for me to make a game with sprites.
But now i can't even get sprites on the screen??
So i used an example named : Complex_2d from devoto.
Ok got the sprites working now! but only on hardware!!
When i start my compiled program on my hardware ds then it runs, but on the emulator it wont work anymore.
a few months ago i used it to test my codes, because writing it the whole time to my flashcard takes a lot of time.
But now it won't work anymore on dualis???
What's going wrong with the new development area???? I really don't know??
here's my code :
i only get a dark screen with a block on topleft???
Hope you guys know the problem??
thanx anyway!!
Everything seems to been changed a littlebit.
Im now trying to make a puzzle game with sprites, but 3 months before it was realy easy for me to make a game with sprites.
But now i can't even get sprites on the screen??
So i used an example named : Complex_2d from devoto.
Ok got the sprites working now! but only on hardware!!
When i start my compiled program on my hardware ds then it runs, but on the emulator it wont work anymore.
a few months ago i used it to test my codes, because writing it the whole time to my flashcard takes a lot of time.
But now it won't work anymore on dualis???
What's going wrong with the new development area???? I really don't know??
here's my code :
Code: |
#include <stdlib.h> #include <nds.h> // these files are generated automatically by the bin2o rule #include "ballpalette_bin.h" #include "balldata_bin.h" #define NUM_SPRITES 36 sSpriteEntry OAMCopySub[128]; //simple sprite struct typedef struct { int x,y; //location int dx, dy; //speed sSpriteEntry* oam; int gfxID; //graphics lovation }Sprite; //--------------------------------------------------------------------------------- void MoveSprite(Sprite* sp) { //--------------------------------------------------------------------------------- int x = sp->x >> 8; int y = sp->y >> 8; sp->oam->attribute[1] &= 0xFE00; sp->oam->attribute[1] |= (x & 0x01FF); sp->oam->attribute[0] &= 0xFF00; sp->oam->attribute[0] |= (y & 0x00FF); } //--------------------------------------------------------------------------------- void initOAM(void) { //--------------------------------------------------------------------------------- int i; for(i = 0; i < 128; i++) { OAMCopySub[i].attribute[0] = ATTR0_DISABLED; } } //--------------------------------------------------------------------------------- void updateOAM(void) { //--------------------------------------------------------------------------------- unsigned int i; for(i = 0; i < 128 * sizeof(sSpriteEntry) / 4 ; i++) { ((uint32*)OAM_SUB)[i] = ((uint32*)OAMCopySub)[i]; } } //--------------------------------------------------------------------------------- void irqVBlank(void) { //--------------------------------------------------------------------------------- IF = IF; } //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- uint16* back = VRAM_A; uint16* front = VRAM_B; Sprite sprites[NUM_SPRITES]; int i, j; int ix = 0; int iy = 0; int screen = 1; uint16* map0 = (uint16*)SCREEN_BASE_BLOCK_SUB(1); uint16* map1 = (uint16*)SCREEN_BASE_BLOCK_SUB(2); uint16 red; //turn on the power to the system powerON(POWER_ALL); //set main display to render directly from the frame buffer videoSetMode(MODE_FB1); //set up the sub display videoSetModeSub(MODE_0_2D | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_ACTIVE | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE ); //vram banks are somewhat complex vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE); //irqs are nice irqInit(); irqSet(IRQ_VBLANK, irqVBlank); // Sprite initialisation for(i = 0; i < 256; i++) SPRITE_PALETTE_SUB[i] = ((u16*)ballpalette_bin)[i]; /* for(i = 0; i< 512; i++) SPRITE_GFX_SUB[i] = ((u16*)balldata_bin)[i]; for(i = 512; i< 1024; i++) SPRITE_GFX_SUB[i] = ((u16*)balldata_bin)[i-256]; */ for(i=0; i<1024*6; i++) { SPRITE_GFX_SUB[i] = ((u16*)balldata_bin)[i]; } //turn off sprites initOAM(); for(i = 0; i < 6; i++) { for(j = 0; j < 6; j++) { sprites[j].x = (0 << 8); } for(j = 7; j < 13; j++) { sprites[j].x = (33 << 8); } sprites[i].y = (32*i << 8); sprites[i].oam = &OAMCopySub[i]; sprites[i].gfxID = 0; //set up our sprites OAM entry attributes sprites[i].oam->attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE; sprites[i].oam->attribute[1] = ATTR1_SIZE_32; sprites[i].oam->attribute[2] = i*32; } BG_PALETTE_SUB[0] = RGB15(10,10,10); BG_PALETTE_SUB[1] = RGB15(0,16,0); BG_PALETTE_SUB[2] = RGB15(0,0,31); while (1) { //move the sprites for(i = 0; i < NUM_SPRITES; i++) { sprites[i].x += sprites[i].dx; sprites[i].y += sprites[i].dy; //check for collision with the screen boundries if(sprites[i].x < (1<<8) || sprites[i].x > (247 << 8)) sprites[i].dx = -sprites[i].dx; if(sprites[i].y < (1<<8) || sprites[i].y > (182 << 8)) sprites[i].dy = -sprites[i].dy; //reposition the sprites MoveSprite(&sprites[i]); } swiWaitForVBlank(); updateOAM(); /* //flip screens if(screen) { videoSetMode(MODE_FB1); front = VRAM_B; back = VRAM_A; screen = 0; } else { videoSetMode(MODE_FB0); front = VRAM_A; back = VRAM_B; screen = 1; } */ } return 0; } |
i only get a dark screen with a block on topleft???
Hope you guys know the problem??
thanx anyway!!