#117389 - Zubrow - Sun Feb 04, 2007 4:44 pm
Here's my noob problem: I'm learning nds coding, to begin I'm trying to display a basic sprite on the main screen and make it move with the sub screen.
My code looks like this
Main.cpp:
I use my own class to handle sprite
Sprite.cpp: (ripped)
That's work with many emulator (like Dualis), but I get a black screen on my NDS ( I use a M3 Simply to run my code ).
So what's wrong with my code ?
Thanks.
Last edited by Zubrow on Mon Feb 05, 2007 10:26 am; edited 1 time in total
My code looks like this
Main.cpp:
Code: |
void OnIrq(void) { if(REG_IF & IRQ_VBLANK) { VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK; REG_IF |= IRQ_VBLANK; } } int main(void) { irqInit(); irqSet(IRQ_VBLANK, OnIrq); powerON(POWER_ALL_2D); videoSetMode(MODE_3_2D|DISPLAY_SPR_ACTIVE|DISPLAY_SPR_1D|DISPLAY_SPR_1D_LAYOUT); vramSetBankA(VRAM_A_MAIN_SPRITE); for (int i = 0; i < 128; ++i) { sSpriteEntry* pSprite = reinterpret_cast<sSpriteEntry*>(reinterpret_cast<u8*>(OAM) + i * sizeof (sSpriteEntry)); pSprite->attribute[0] = ATTR0_DISABLED; } for (int i = 0; i < 128; ++i) { sSpriteEntry* pSprite = reinterpret_cast<sSpriteEntry*>(reinterpret_cast<u8*>(OAM_SUB) + i * sizeof (sSpriteEntry)); pSprite->attribute[0] = ATTR0_DISABLED; } swiCopy(ProphetTiles, SPRITE_GFX, ProphetTilesLen); swiCopy(ProphetPal, SPRITE_PALETTE, ProphetPalLen); CSprite Prophet1(ATTR0_COLOR_256|ATTR0_SQUARE|(SCREEN_WIDTH >> 1) - 96, ATTR1_SIZE_64|(SCREEN_HEIGHT >> 1), 0|ATTR2_ALPHA(1)); CSprite Prophet2(ATTR0_COLOR_256|ATTR0_SQUARE|(SCREEN_WIDTH >> 1) - 32, ATTR1_SIZE_64|(SCREEN_HEIGHT >> 1), 128|ATTR2_ALPHA(1)); Prophet1.Update(); Prophet2.Update(); touchPosition tp; for (;;) { tp = touchReadXY(); if (tp.x != 0 && tp.y != 0) { Prophet1.GoTo(tp.px, tp.py); Prophet2.GoTo(tp.px, tp.py+64); Prophet1.Update(); Prophet2.Update(); } } return 0; } |
I use my own class to handle sprite
Sprite.cpp: (ripped)
Code: |
CSprite::CSprite(u16 Attr0, u16 Attr1, u16 Attr2) { m_SpriteEntry.attribute[0] = Attr0; m_SpriteEntry.attribute[1] = Attr1; m_SpriteEntry.attribute[2] = Attr2; m_SpriteRotation.hdx = 256; m_SpriteRotation.hdy = 0; m_SpriteRotation.vdx = 0; m_SpriteRotation.vdy = 256; static u16 Id; m_SpriteId = Id++; } void CSprite::Update(void) { dmaCopy(&m_SpriteEntry, OAM + ((sizeof (sSpriteEntry) >> 1) * m_SpriteId), sizeof (sSpriteEntry)); } |
That's work with many emulator (like Dualis), but I get a black screen on my NDS ( I use a M3 Simply to run my code ).
So what's wrong with my code ?
Thanks.
Last edited by Zubrow on Mon Feb 05, 2007 10:26 am; edited 1 time in total