#49509 - QuantumDoja - Sat Jul 30, 2005 6:51 pm
Hi, I have a game im writing, I have 2 emulators, NO$GBA and visual boy advance, when I load my game up things appear as expected, the sprite appears on the screen, stationary....when i put the rom onto my gameboy however, it moves off the screen!
*I have a funny feeling Ive missed something important out of my code.
here is my game loop
Code: |
//Game Loop
DoIntro(); //sets a mode 4 welcome screen
DoMenu();
while(1) {
SetMode(MODE_0 | OBJ_ENABLE | OBJ_MAP_1D);
LoadAssets(iLevelNumber);
while(1) {
getInput();
MoveSprite(&sprites[0],PlayerSprite.x,PlayerSprite.y);
SpriteAnimation();
WaitForVsync();
CopyOAM();
UpdateBackground(&bg0);
UpdateBackground(&bg1);
UpdateBackground(&bg2);
UpdateBackground(&bg3);
}
}
|
_________________
Chris Davis
#49511 - tepples - Sat Jul 30, 2005 6:53 pm
What does your WaitForVsync look like? And are you using a BIOS file with the emulators? (A BIOS file improves accuracy, but you have to dump it yourself using a flash card.)
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#49512 - QuantumDoja - Sat Jul 30, 2005 6:55 pm
Hi...my vsync looks like this...
Code: |
//VSYNC - wait for screen to stop drawing.
void WaitForVsync() {
while((volatile u16)REG_VCOUNT != 160) {}
}
|
_________________
Chris Davis
#49514 - tepples - Sat Jul 30, 2005 7:06 pm
This won't fix your main problem, but if you're not yet using the SWI, your WaitForVsync() should look like this:
Code: |
//VSYNC - wait for screen to stop drawing.
void WaitForVsync() {
while((volatile u16)REG_VCOUNT == 160) {}
while((volatile u16)REG_VCOUNT != 160) {}
} |
Otherwise, if one iteration of your game loop executes within 1232 cycles (one scanline), it skips the waiting.
Now, what do getInput() and SpriteAnimation() do?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#49515 - QuantumDoja - Sat Jul 30, 2005 7:12 pm
ok...the other two functions do...
Code: |
void getInput() {
u16 loop;
if (keyDown(KEY_LEFT)) {
PlayerSprite.x--;
PlayerSprite.Animation = &Anim0;
}
if (keyDown(KEY_RIGHT)) {
PlayerSprite.x++;
PlayerSprite.Animation = &Anim1;
}
if (keyDown(KEY_UP)) {
PlayerSprite.y--;
}
if (keyDown(KEY_DOWN)) {
PlayerSprite.y++;
}
}
|
Code: |
void SpriteAnimation(void) {
if (framecounter > PlayerSprite.Animation->times[PlayerSprite.Animation->Current]) {
memcpy( (u16 *)0x06010000, PlayerSprite.Animation->sequence[PlayerSprite.Animation->Current], sizeof(PlayerData4) );
if (PlayerSprite.Animation->Current == PlayerSprite.Animation->NumberOfFrames) {
PlayerSprite.Animation->Current = -1;
}
PlayerSprite.Animation->Current++;
framecounter = 0;
}
framecounter++;
}
|
As I have a struct defining a player, the .Animation specifies what animation to play, from a struct.
Code: |
Anim0.Current = 0;
Anim0.NumberOfFrames = 1;
Anim0.sequence[0] = &PlayerData6;
Anim0.sequence[1] = &PlayerData3;
Anim0.times[0] = 5;
Anim0.times[1] = 5;
|
_________________
Chris Davis
#49518 - tepples - Sat Jul 30, 2005 7:57 pm
Are you sure keyDown is doing what you think it's doing?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#49520 - QuantumDoja - Sat Jul 30, 2005 8:45 pm
I think this is where the problem is hiding...as up/down works on the emulator, but not on hardware....i will investigate...thanks for the help.
_________________
Chris Davis