#103864 - TheWopr - Mon Sep 25, 2006 1:04 am
Still working on the same game, if you don't know what it is check my other posts, and i've come across another problem. My program runs at a good speed, but its really choppy, sometimes it goes slower and then jumps faster.
I have a feeling i know whats wrong, i'm not waiting for the vblank. My problem is that i'm using mode_5_2D for my main screen, but all the tutorials i've seen that wait for the vblank, are in Framebuffer mode, i tried copying their code anyway but it keeps returning a whole bunch of errors. Anyone have code for waiting for the vblank on mode_5? If this is even my problem? Thanks in advance
#103891 - josath - Mon Sep 25, 2006 5:03 am
in your init code, put:
Code: |
irqInit();
irqSet(IRQ_VBLANK, 0); |
then to wait for vblank, call:
Code: |
swiWaitForVBlank(); |
#103989 - TheWopr - Mon Sep 25, 2006 9:21 pm
Ok i tried that and heres my code, above it i used irq_init() and irqSet(IRQ_VBLANK, 0);
Code: |
while(1) {
scanKeys();
doInputStuff();
updatePlayers();
BG_GFX[(int)(player1.x + ((int)player1.y)*256)] = RGB15(0,31,0) | BIT(15);
swiWaitForVBlank();
} |
Now all it does is pause until I hit a key or something, it stops in the while loop whenever it gets to swiWaitForVBlank(). As you can tell i'm just polling for the key's. Thats pretty much it, any more help?
#103995 - Lick - Mon Sep 25, 2006 9:33 pm
Please show us doInputStuff, I think the problem lies in that function.
_________________
http://licklick.wordpress.com
#103996 - TheWopr - Mon Sep 25, 2006 9:35 pm
Hope this isn't too long for the forum but here it goes.....
Code: |
void doInputStuff() {
if(keysDown() & KEY_UP) {
player1.dy = -player1.speed; }
if(keysDown() & KEY_DOWN){
player1.dy = player1.speed; }
if(keysDown() & KEY_LEFT){
player1.dx = -player1.speed; }
if(keysDown() & KEY_RIGHT){
player1.dx = player1.speed; }
if(keysUp() & KEY_UP) {
player1.dy = 0; }
if(keysUp() & KEY_DOWN){
player1.dy = 0; }
if(keysUp() & KEY_LEFT){
player1.dx = 0; }
if(keysUp() & KEY_RIGHT){
player1.dx = 0; }
} |
#103998 - Lick - Mon Sep 25, 2006 9:39 pm
Weird, I see nothing wrong with it.. =/
_________________
http://licklick.wordpress.com
#103999 - TheWopr - Mon Sep 25, 2006 9:47 pm
Wow, sorry guys, i realized that what i did was that the keyUp() had it set the speed back to 0 which i didn't even think of >.< i know how to fix it now but thanks for the help lick.
#104000 - sajiimori - Mon Sep 25, 2006 9:55 pm
That approach can be fragile sometimes, and bugs can lead to getting stuck going in a direction. I'd recommend clearing your velocity every tick and then adding to it based on input.
#104006 - TheWopr - Mon Sep 25, 2006 11:02 pm
Sajiimori: I see what your saying, but in this game i actually want people to stay in the direction that they press, similar games would be Surround(Atari) Tron(Atari) Nibbles(Everything) and I'm sure there are plenty of others.
#104007 - sajiimori - Mon Sep 25, 2006 11:05 pm
Oh, I guess I was confused because you were clearing velocity when the key is released.