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

Please ignore issue fixed

J

Jack

Guest
Hey, I have an animation bug atm. I know the problem just not how to fix it.:bash:
My problem is that when my player spawns in he is rolling through the attack animation automatically even though its supposed to be only when you press X. I have tried to fix this only to mess up something else so if you have a solution PLEASE tell me. Thanks! :) (this is a brand new project so barely any code yet.

Step Event:
//sprites

//LR animations (working fine)
if (keyboard_check(ord('D'))) {
image_index=1;
}
if (keyboard_check(ord('A'))) {
image_index=2;
}
//attack animation (broken)
if (keyboard_check(ord('X'))) {
sprite_index = spr_player_attack
image_speed = 1;
}
else
{
sprite_index = spr_player;
}
//player movement
hspeed = flyspd * (keyboard_check(ord('D')) - keyboard_check(ord('A')));
vspeed = flyspd * (keyboard_check(ord('S')) - keyboard_check(ord('W')));



//collisions
if hspeed!=0
if !place_free(x+hspeed,y)
{
if hspeed>0 move_contact_solid(0,hspeed)
if hspeed<0 move_contact_solid(180,-hspeed)
hspeed=0
}

if vspeed!=0
if !place_free(x+hspeed,y+vspeed)
{
if vspeed>0 move_contact_solid(270,vspeed)
if vspeed<0 move_contact_solid(90,-vspeed)
vspeed=0
}
 
P

PlayLight

Guest
Same problem as your other post.
You are using the step event to set your sprite index with keyboard_check.

keyboard_check will return 1 if the specified key is currently being held down, so in this case your sprite index is being reset to 'spr_player_attack' (at image_index: 0 ) every step while your holding down the X key.

If you really want to use the above setup in the step event, then you'll need to change your code to something like:
Code:
if ( keyboard_check_pressed( ord('X') ) )
    {
    sprite_index = spr_player_attack;
    }
if ( keyboard_check_released( ord('X') ) )
    {
    sprite_index = spr_player;
    }
Also make sure to set your sprite_index to spr_player in the create event.
 
Top