Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
I'm having issues getting my metasprite to move to the right. It has no issue with going to the left, and even animates correctly when moving to the left. However when moving to the right it locks up and refuses to move to the right. The first time the right arrow is hit the sprite moves right then back left immediately. Can someone take a look at my code below and see if I am missing something? I copied and pasted the code, so I don't think I have a typo there or an error in the logic.
#include <gb/gb.h>
#include <stdio.h>
#include "spirit.c"
void main(){
int x = 55;
int y =136;
SPRITES_8x16;spirit);
set_sprite_tile(0,0);
move_sprite(0,x,y);
set_sprite_tile(1,2);
move_sprite(1,x+8, y);
SHOW_SPRITES;
while(1){
if(joypad==J_RIGHT)
{
x + 16;
scroll_sprite(0,x,y);
scroll_sprite(1,x+8,y);
delay(10);
set_sprite_tile(1,2);
delay(10);
set_sprite_tile(1,6);
delay(10);
set_sprite_tile(1,2);
delay(10);
}
if(joypad==J_LEFT)
{
x - 16;
scroll_sprite(0,x,y);
scroll_sprite(1,x+8,y);
delay(10);
set_sprite_tile(0,1);
delay(10);
set_sprite_tile(0,4);
delay(10);
set_sprite_tile(0,1);
delay(10);
}
}
Offline
The code for changing the x position is wrong:
x + 16; x - 16;
It should be...
x = x + 16; x = x - 16;
...or the shorthand versions...
x += 16; x -= 16;
In fact it's strange that it would move left. The code should not actually be changing x at all.
Offline
nitro,
You are absolutely correct. I forgot to include ()'s in my if statement after joypad which prevented Visual Studio from creating the new .gb file. I did not notice this until I expanded the terminal and saw the error statements. So the times where it allowed me to move left was from a previously compiled version (using -- decrementing) that was able to generate the .gb file. Once I solved that the sprite did not move until I updated it with the correct += and -=
Thank you for the help!
Offline