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);
//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);