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

Full animation not showing and looping with quick button presses

T

TimKilgore

Guest
Hi everyone,

I'm working on a beat 'em up game and I'm having a couple of problems with my animations.

The quick and dirty of what my code does is character walks right and left with arrow keys. Character runs right and left if you double tap the right or left arrow keys. Ctrl will punch, Alt will kick and hitting both does a special attack while standing and while running.

If I hit Ctrl then Alt in quick succession the character will kick repeatedly. Same with running but usually it will repeat the running special attack.

The other issue is that when there are multiple frames of animation when I'm hitting either the Ctrl or Alt button on the last frame of the animation is playing not the whole animation about 50% of the time. It depends on how quickly you hit the button. If you tap it quickly just the last frame will show, if you hit the button deliberately the whole animation will play.

The first part of the code is in the Step Event of the Player Object

Code:
////Button Presses

/// Sets which way the character is facing
image_xscale=image_flipped_variable


/// All animations related to pressing control Button (punch)
if keyboard_check_pressed(vk_control) = true && keyboard_check_pressed(vk_alt) = false && ISRunning = 0
{
ISPunching=1
}

if keyboard_check_pressed(vk_control) = true && keyboard_check_pressed(vk_alt) = false && ISRunning = 1
{
ISRunning = 0
hspeed = 0
ISRunPunch = 1
}

if ISPunching = 1
{
    if ComboCounter > 3
    {
    hspeed = 0
    sprite_index = SPR_PlayerStrongPunch
    image_speed = 0.15
    image_xscale = image_flipped_variable
        if (sprite_index == SPR_PlayerStrongPunch && image_index>1.9 && image_index <2.2)
        {
        instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_StrongPunch)
        OBJ_StrongPunch.image_xscale=OBJ_Player.image_flipped_variable
        }
    }
   
    if ComboCounter <= 3
    {
    hspeed = 0
    sprite_index = SPR_PlayerBasicPunch
    image_speed = 0.25
    image_xscale = image_flipped_variable
        if (sprite_index == SPR_PlayerBasicPunch && image_index>1.9 && image_index <2.2)
        {
            instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_BasicPunch)
            OBJ_BasicPunch.image_xscale=OBJ_Player.image_flipped_variable
        }
    }
   
}

if ISRunPunch = 1
{
hspeed = (image_flipped_variable*-2)
sprite_index = SPR_PlayerRunningPunch
image_speed = 0.12
image_xscale = image_flipped_variable
    if (sprite_index = SPR_PlayerRunningPunch && image_index>2.9 && image_index<3.2)
    {
        instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_RunPunch)
        OBJ_RunPunch.image_xscale=OBJ_Player.image_flipped_variable
    }
}


/// All animations related to pressing alt Button (kick)
if keyboard_check_pressed(vk_alt) = true && keyboard_check_pressed(vk_control) = false && ISRunning = 0
{
ISKicking=1
}

if keyboard_check_pressed(vk_alt) = true && keyboard_check_pressed(vk_control) = false && ISRunning = 1
{
ISRunning = 0
hspeed = 0
ISRunKick = 1
}

if ISKicking = 1
{
    if KickComboCounter > 3
    {
    hspeed = 0
    sprite_index = SPR_PlayerStrongKick
    image_speed = 0.15
    image_xscale = image_flipped_variable
        if (sprite_index == SPR_PlayerStrongKick && image_index>2.9 && image_index <3.2)
        {
        instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_StrongKick)
        OBJ_StrongKick.image_xscale=OBJ_Player.image_flipped_variable
        }
    }
   
    if KickComboCounter <= 3
    {
    hspeed = 0
    sprite_index = SPR_PlayerBasicKick
    image_speed = 0.25
    image_xscale = image_flipped_variable
        if (sprite_index == SPR_PlayerBasicKick && image_index>2.9 && image_index <3.2)
        {
            instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_BasicKick)
            OBJ_BasicKick.image_xscale=OBJ_Player.image_flipped_variable
        }
    }
}

if ISRunKick = 1
{
hspeed = (image_flipped_variable*-2)
sprite_index = SPR_PlayerRunningKick
image_speed = 0.15
image_xscale = image_flipped_variable
    if (sprite_index = SPR_PlayerRunningKick && image_index>1.9 && image_index<3.2)
    {
        instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_RunKick)
        OBJ_RunKick.image_xscale=OBJ_Player.image_flipped_variable
    }
}


/// All animations related to pressing control and alt Buttons (special)
if (keyboard_check_pressed(vk_control) = true && keyboard_check_pressed(vk_alt) = true) && ISRunning = 0
{
IsSpecial=1
}

if (keyboard_check_pressed(vk_control) = true && keyboard_check_pressed(vk_alt) = true) && ISRunning = 1
{
ISRunning = 0
hspeed = 0
IsRunSpecial = 1
}

if IsSpecial = 1
{
    hspeed = 0
    sprite_index = SPR_PlayerSpecial
    image_speed = 0.25
    image_xscale = image_flipped_variable
        if (sprite_index == SPR_PlayerSpecial && image_index>1.9 && image_index <2.2)
        {
            instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_Special)
            OBJ_Special.image_xscale=OBJ_Player.image_flipped_variable
        }
}

if IsRunSpecial = 1
{
hspeed = (image_flipped_variable*-2)
sprite_index = SPR_PlayerRunningSpecial
image_speed = 0.15
image_xscale = image_flipped_variable
    if (sprite_index = SPR_PlayerRunningSpecial && image_index>2.9 && image_index<3.2)
    {
        instance_create_depth(OBJ_Player.x,OBJ_Player.y,OBJ_Player.depth,OBJ_RunSpecial)
        OBJ_RunSpecial.image_xscale=OBJ_Player.image_flipped_variable
    }
}


/// if alarm is greater than 0 then character runs
if keyboard_check(vk_left) = true && alarm[1]>0
{
    ISRunning = 1
}

if keyboard_check(vk_right) = true && alarm[1]>0
{
    ISRunning = 1
}

if keyboard_check(vk_left) = true && ISRunning = 0
{
hspeed = -3
image_flipped_variable = 1
sprite_index = SPR_PlayerWalking
image_speed = 0.5
image_xscale = image_flipped_variable
}

if keyboard_check(vk_left) = true && ISRunning = 1
{
hspeed = -6
image_flipped_variable = 1
sprite_index = SPR_PlayerRunning
image_speed = 0.5
image_xscale = image_flipped_variable
}


if keyboard_check(vk_right) = true && ISRunning = 0
{
hspeed = 3
image_flipped_variable = -1
sprite_index = SPR_PlayerWalking
image_speed = 0.5
image_xscale = image_flipped_variable
}

if keyboard_check(vk_right) = true && ISRunning = 1
{
hspeed = 6
image_flipped_variable = -1
sprite_index = SPR_PlayerRunning
image_speed = 0.5
image_xscale = image_flipped_variable
}

if keyboard_check(vk_left) = false && keyboard_check(vk_right) = false && keyboard_check_pressed(vk_alt) = false && ISKicking = 0 && keyboard_check_pressed(vk_control) = false && ISPunching = 0 && ISRunning = 0 && ISRunPunch = 0 && ISRunKick = 0 && IsSpecial = 0 && IsRunSpecial = 0
{
hspeed = 0
image_xscale = image_flipped_variable
sprite_index = SPR_PlayerIdle
}

///sets alarm for double tap to run
if keyboard_check_released(vk_left)
{
alarm[1] = 5
ISRunning = 0
}

if keyboard_check_released(vk_right)
{
alarm[1] = 5
ISRunning = 0
}
The Second part of the code is in the Animation End Event

Code:
if sprite_index = SPR_PlayerBasicPunch
{
ISPunching = 0
alarm[0] = 30
ComboCounter = ComboCounter+1
}

if sprite_index = SPR_PlayerStrongPunch
{
ISPunching = 0
ComboCounter = 0
}

if sprite_index = SPR_PlayerBasicKick
{
ISKicking = 0
alarm[0] = 30
KickComboCounter = KickComboCounter+1
}

if sprite_index = SPR_PlayerMedKick
{
ISKicking = 0
alarm[0] = 30
KickComboCounter = KickComboCounter+1
}

if sprite_index = SPR_PlayerStrongKick
{
ISKicking = 0
KickComboCounter = 0
}

if sprite_index = SPR_PlayerRunningPunch
{
ISRunPunch = 0
IsRunSpecial = 0
ISRunKick = 0
}

if sprite_index = SPR_PlayerRunningKick
{
ISRunKick = 0
IsRunSpecial = 0
ISRunPunch = 0
}

if sprite_index = SPR_PlayerSpecial
{
IsSpecial = 0
ISPunching = 0
ISKicking = 0
ISRunPunch = 0
ISRunKick = 0
}

if sprite_index = SPR_PlayerRunningSpecial
{
IsRunSpecial = 0
ISRunPunch = 0
ISRunKick = 0
ISPunching = 0
ISKicking = 0
}
Any thoughts on how to correct this? I think it might be a problem with how the keyboard is being recognized and if I switch to using a gamepad there shouldn't be these issues because they're meant to be hit rapidly not like the keyboard. Previously I was having issues with both buttons being hit at once because I had selected the Z and the X keys which the computer didn't recognize as supposed to be hit simultaneously.

Thanks for all your help.
 

Relic

Member
For your second issue (not showing the whole animation) when you change to the punch sprite or the kick sprite you will also need to set image_index to zero. Changing sprite_index does not make the sprite play from the beginning by default.
 
Top