• 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!

animation playing issue

X

Xavion

Guest
please see my latest reply for the issue.

Hello, I've been having some problems in my platformer trying to get my crouching and rising animations to play. once I press down ("S" in this case) I'm trying to have my character play a crouch animation, then once the player has completely finished the crouch animation they will pause in that state until the player isn't holding down anymore, in which case the player will start playing a rise animation, and once the player finishes the rise animation they will go back to there regular idle animation. I'm not sure how to set up the crouching part as I stated earlier, but even when I just try to play the crouch animation it just makes my character's image speed and index become 0. I actually figured out the rising part, the animation part of it just doesn't play though.

Here's the create event:

Code:
///Initialize check
grav = 0.8;
hsp = 0;
vsp = 0;
jumpspeed = 25;
movespeed = 4;
rotating = false;
can_walk = false;
start_walk = true;
grounded = true;
crouching = false;
rising = false;
Here's the step event:
Code:
///Actions and Animations

///////Get the Player's input////////
if crouching = false and rising = false
{
    key_right = keyboard_check(ord("D"));
    key_left = -keyboard_check(ord("A"));
}
if grounded = true and crouching = false and rising = false
{
    key_jump = keyboard_check_pressed(ord("J"));
}
if grounded = true
{
    crouching = keyboard_check(ord("S"));
}
///////React to inputs/////////
if crouching = true or rising = true
{
hsp = 0
}

move = key_left + key_right;
if crouching = false and rising = false
{
hsp = move * movespeed;
}
if (vsp < 25) vsp += grav;
if (place_meeting(x, y+1, obj_wall))
{
    grounded = true
    vsp = key_jump * -jumpspeed
}
else
{
grounded = false
}

///////Horizontal Collision///////
if (place_meeting(x+hsp,y,obj_wall))
{
    while(!place_meeting(x+sign(hsp),y,obj_wall))
    {
        x += sign(hsp);
    }
    hsp = 0;

}
x += hsp;

////////Vertical Collision/////////
if (place_meeting(x,y+vsp,obj_wall))
{
    while(!place_meeting(x,y+sign(vsp),obj_wall))
    {
        y += sign(vsp);
    }
    vsp = 0;

}

y += vsp;

/////////////////Animation/////////////////
image_speed = 1/4;
if grounded = true
{
if crouching = true
image_index = spr_player_crouch;
}
if grounded = true && crouching = false

    if ( keyboard_check(ord("A")) and image_xscale = 1 && !can_walk && !rotating )
    {
        alarm[0]= 10;  // This alarm is for rotating animation
        sprite_index = spr_player_rotate;
        image_xscale = -1;
        image_index = 0
        rotating = true;
    }
    else
    if ( keyboard_check(ord("D")) and image_xscale = -1 && !can_walk && !rotating )
    {
        alarm[0]= 10;  // This alarm is for rotating animation
        sprite_index = spr_player_rotate;
        image_xscale = 1;
        image_index = 0
        rotating = true;
    }
 
    //Idle Animation Check
    if ((keyboard_check_released(ord("D")) || keyboard_check_released(ord("A"))) or (movespeed = 0) && !rotating )
    {
        can_walk = false
        sprite_index = spr_player_idle;
        start_walk = true
    }
    //Walk check
    if ( can_walk )
    or ( keyboard_check(ord("D")) and image_xscale = 1 and sprite_index =! spr_player_rotate)
    or ( keyboard_check(ord("A")) and image_xscale = -1 and sprite_index =! spr_player_rotate)
    {
        sprite_index = spr_player_walk; // your walking sprite here
    }
    //Start Walk
    if ( keyboard_check_pressed(ord("A")) and image_xscale = -1 and start_walk = true && !can_walk && !rotating)
 
    {
        alarm[2]= 10;  // This alarm is for walk start animation
        sprite_index = spr_player_walk_start;
        image_xscale = -1;
        image_index = 0
        image_speed = 1/5
    }
    else
    if ( keyboard_check_pressed(ord("D")) and image_xscale = 1 and start_walk = true && !can_walk && !rotating)
 
    {
        alarm[2]= 10;  // This alarm is for walk start animation
        sprite_index = spr_player_walk_start;
        image_xscale = 1;
        image_index = 0
        image_speed = 1/5;
    }
//Crouching
if  keyboard_check(ord("S")) and crouching = true
{
    image_index = spr_player_crouch
}
//Rising
if (keyboard_check_released(ord("S"))) and grounded = true
{
    rising = true
    image_index = spr_player_rise
    alarm[4]= 15;
}
Alarm 0
Code:
///Variable Initializer
rotating = false;
can_walk = true;

alarm[1]= 1;
Alarm1
Code:
///Idle Animation Check
if (hsp = 0)
can_walk = false;
sprite_index = spr_player_idle;
Alarm2
Code:
start_walk = false;
image_index = 0
{
sprite_index = spr_player_walk;
}
alarm[3]= 1;
Alarm 3
Code:
sprite_index = spr_player_idle;
Alarm 4
Code:
rising = false

It's not necessary but if anyone also knows how to change the mask of the player depending on the crouch and rise sub images that would be great as well. Thanks!
 
Last edited by a moderator:
B

bojack29

Guest
You should look into using finite state machines for your character. They will make your life soooooooooooooo much easier.
 

M. Idrees

Member
Code:
if ( sprite_index == spr_rotating )
{
    if ( image_index == 4 )
    {
     mask_index = mask_rotating;
    }
}
And one another thing you left the [ if ] from below code I think

Alarm[2]

start_walk = false;
<--> image_index = 0
{
sprite_index = spr_player_walk;
}
alarm[3]= 1;
 
X

Xavion

Guest
You should look into using finite state machines for your character. They will make your life soooooooooooooo much easier.
Ok, that's going to make things so much more simple. I appreciate it.
 
Last edited by a moderator:
X

Xavion

Guest
Code:
if ( sprite_index == spr_rotating )
{
    if ( image_index == 4 )
    {
     mask_index = mask_rotating;
    }
}
And one another thing you left the [ if ] from below code I think

Alarm[2]

start_walk = false;
<--> image_index = 0
{
sprite_index = spr_player_walk;
}
alarm[3]= 1;
I did forget that "if". that code will help a lot, thank you.
 
Last edited by a moderator:
X

Xavion

Guest
Ok, so i finally finished changing my code to states and its way more manageable now. my animation still doesn't play when i start crouching though.

Here's the code

Crouching state:

Code:
hsp = 0
vsp = 0

image_speed = 1/4;
image_index = spr_player_crouch;
scr_player_collide();
//Rising
if (keyboard_check_released(ord("S")))
{
    image_index = spr_player_rise
    alarm[4]= 15;
}
image_speed = 1/4;
Alarm 4

Code:
state = states.normal;
the weird thing is everything about this code plays perfectly except for the animation parts of it. My character's animation just seems to completely pause without changing sprites when I press down. I feel as though I'm missing something very little but I just can't figure it out.

Also, to try to understand the problem I put a animation code in a completely different object's step event, and the only code in this object is this code I put in it's step event:

Code:
image_index = spr_player_crouch;
image_speed = 1/4;
And it pauses just like my player.

Edit: Nvm It turns out my problem was using image_index instead of sprite_index. My bad
 
Last edited by a moderator:
Top