GameMaker Help

J

James Lin

Guest
if (sign(move_x) = 1)
{
sprite_index = sLeft
image_speed = 1;
last_move = "Left"

}
if (sign(move_x) = -1)
{
sprite_index = sRight
image_speed = 1;
last_move = "Right"

}
if (sign(move_x) and sign(move_y) = 0)
{

if (last_move = "Down") image_index = sDownIdle;
if (last_move = "Up") image_index = sUpIdle;
if (last_move = "Left") image_index = sLeftIdle;
if (last_move = "Right") image_index = sRightIdle;
image_speed = 0;
}
if (sign(move_y) = 1)
{
sprite_index = sUp
image_speed = 1;
last_move = "Up"

}
if (sign(move_y) = -1)
{
sprite_index = sDown
image_speed = 1;
last_move = "Down"

}
I need help the code does not work for the left animation and the idle animations
 
J

James Lin

Guest
That can be read as "if sign(move_x) evaluates to true and sign(move_y) equals zero".

See: How NOT to use && and ||

If you're still facing problems, please post the code where you set move_x.
if (left_key == true and move_x == 0){
move_x = 1
}
if (right_key == true and move_x == 0){
move_x = -1
}
move_y = 0;
if (up_key == true and move_y == 0){
move_y = 1
}
if (down_key == true and move_y == 0){
move_y = -1
}

if (sign(move_x) == 1)
{
sprite_index = sLeft
image_speed = 1;
last_move = "Left"

}
if (sign(move_x) == -1)
{
sprite_index = sRight
image_speed = 1;
last_move = "Right"

}

if (sign(move_y) == 1)
{
sprite_index = sUp
image_speed = 1;
last_move = "Up"

}
if (sign(move_y) == -1)
{
sprite_index = sDown
image_speed = 1;
last_move = "Down"

}
if (sign(move_x) == 0 and sign(move_y) == 0)
{
image_speed = 0;
if (last_move = "Down") image_index = sDownIdle;
if (last_move = "Up") image_index = sUpIdle;
if (last_move = "Left") image_index = sLeftIdle;
if (last_move = "Right") image_index = sRightIdle;
image_speed = 0;
}
if (!place_meeting(x - move_x * char_speed, y, oWall)){
x = x - move_x * char_speed
}
if (!place_meeting(x , y - move_y * char_speed, oWall)){
y = y - move_y * char_speed
}
First, I am having issues with the idle animations still so not work
 
Last edited by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
You're checking if move_x equals 0, but never setting it to that. The same goes for the y variant.
 

TheouAegis

Member
Code:
if move_x == 0 {
    move_x = (left_key - right_key);
    if move_x != 0 move_y = 0;
}
else
if move_y == 0 {
    move_y = (up_key - down_key);
    if move_y != 0 move_x = 0;
}
Considering you set move_y=0 before checking the up and down keys, I gathered you wanted something like this for movement. Although this would cause a weird, diagonal movement with the sprite rapidly alternating back and forth. But then again, your code didn't say you didn't want that, either.


As IKEcoolcoder was pointing out, you are setting image_index for your idle sprite, when you should be using sprite_index.
 
Top