Code: Select all
//function to read input and store sprite into curr (current sprite frame)
void handleInput(MySprite* curr,MySprite* spriteBank) {
scanKeys();
if (keysHeld() & KEY_UP) {
if(curr->id==0)
curr = &spriteBank[2];
else if(curr->id==2)
curr = &spriteBank[0];
else
curr = &spriteBank[0];
std::cout << "up pressed";
posy-=step;
} else if (keysHeld() & KEY_DOWN) {
if(curr->id==6)
curr = &spriteBank[8];
else if(curr->id==8)
curr = &spriteBank[6];
else
curr = &spriteBank[6];
std::cout << "down pressed";
posy+=step;
} else if (keysHeld() & KEY_LEFT) {
if(curr->id==9)
curr = &spriteBank[11];
else if(curr->id==11)
curr = &spriteBank[9];
else
curr = &spriteBank[9];
std::cout << "left pressed";
posx-=step;
} else if (keysHeld() & KEY_RIGHT) {
if(curr->id==3)
curr = &spriteBank[5];
else if(curr->id==5)
curr = &spriteBank[3];
else
curr = &spriteBank[3];
std::cout << "right pressed";
posx+=step;
} else {
if((curr->id==0)||(curr->id==2))
curr = &spriteBank[1];
else if((curr->id==3)||(curr->id==5))
curr = &spriteBank[4];
else if((curr->id==6)||(curr->id==8))
curr = &spriteBank[7];
else if((curr->id==9)||(curr->id==11))
curr = &spriteBank[10];
std::cout << "stopped";
}
}
//-----///
....
//inside while loop:
swiWaitForVBlank();
oamUpdate(&oamMain);
oamClear(&oamMain,0,0);
if(i%10==0){ //i is just a counter to slow down the frame changing speed
handleInput(&curr,sprite);
consoleClear();
}
i++;
}
Though when I try to run this code I can only see the spriteBank[0] frame....
MySprite curr is initialized as this:
Code: Select all
MySprite curr = sprite[0];
What am I doing wrong? can somebody please help? thanks a lot