• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Help with sprite index changes

R

robeng

Guest
Hello! I wan't to change sprites for my player when I move, jump and when at idle. I have a code but there is one part that wont work.

//Animationer
if (!place_meeting(x,y+1,oWall)) {
sprite_index = sMorotA;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
} else {
image_speed = 1;
if (hsp == 0) {
sprite_index = sMorot;
} else {
sprite_index = sMorotM;
}
}

if (hsp != 0) image_xscale = -sign(hsp);

My player can't move left and right when it is like this. But. if I comment out the whole first else statement I can walk right and left, but then the sprite is wrong. What is wrong with the code?

Thanks in advance!


Whole code:
//Hämtar input
keyLeft = keyboard_check(ord("A"));
keyRight = keyboard_check(ord("D"));
keyJump = keyboard_check(vk_space);

//Räknar ut riktning
var move = keyRight - keyLeft;
hsp = move * walksp;
vsp += grv;
if (place_meeting(x,y+1,oWall)) && (keyJump) {
vsp = -5;
}

//Kollar horisontell kollision
if (place_meeting(x+hsp,y,oWall)) {
while (!place_meeting(x+sign(hsp),y,oWall)) {
x += sign(hsp);
}
hsp = 0;
}
//Flyttar MOROTEN
x += hsp;

//Kollar vertikal kollision
if (place_meeting(x,y+vsp,oWall)) {
while (!place_meeting(x,y+sign(vsp),oWall)) {
y += sign(vsp);
}
vsp = 0;
}

//Flyttar MOROTEN
y += vsp;

//Animationer
if (!place_meeting(x,y+1,oWall)) {
sprite_index = sMorotA;
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
} else {
image_speed = 1;
if (hsp == 0) {
sprite_index = sMorot;
} else {
sprite_index = sMorotM;
}
}

if (hsp != 0) image_xscale = -sign(hsp);
 

Simon Gust

Member
The problem could hide in the actual sprite, the origin might be off or the hitbox is not the same as the other sprite's.
 
Top