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

GameMaker [SOLVED]: Transistion sprite and same button multiple use

Dividious

Member
i need help figuring the proper way to go about this... i have a player that has a (unsheathe sword) animation and then an animation (idle with sword).. my issue is im trying to have the same button control the animation... such as press SHIFT and play (unsheathe sword) animation, continue to HOLD SHIFT and the current animation goes to (idle with sword), and if you let go of the SHIFT key, then the animation reverts to (swordless idle) animation. I'm at a loss, i either end up only having the unsheathe sword animation loop once i hold the button down and i never go into the idle with sword animation...

ideally it'd go

PRESS BUTTON -----> plays unsheathe sword animation
CONTINUE TO HOLD SAME BUTTON + at the end of unsheathe animation -----> transistions to idle with sword animation and continues
BUTTON RELEASED -----> reverts back to swordless idle animation

I appreciate any help or guidance.
 

Dividious

Member
this is the last thing i tried:
Code:
if(engarde_key_held)      
{
    if(sprite_index!=spr_player_idle_sword)
    {
        sprite_index=spr_player_draw_sword;
        image_speed=.30;
if(image_index>image_number-1)
    {
        image_index=4;
        sprite_index=spr_player_idle_sword;
        image_speed=.50;
    }
    }
}
and he plays the draw sword animation, only plays the first frame of the idle sword animation... and then loops.... over and over... been at this for 2 days... getting frustrated... each animation has 4 frames... (0,1,2,3)
 

Yal

šŸ§ *penguin noises*
GMC Elder
I'd say the easiest way to solve this is by finite state machines... you have separate SWORD DRAWN and SWORD SHEATHED states, which runs different code. Easiest way to do this is to have a switch statement in the step event, which runs different code for different states. (For larger projects you could break up each substate into a script to not have a code block with thousands of lines)

In sheathed state, set the sprite to the normal idle sprite, and have your movement code (as a script, because we'll use it in other states too and copypasting code instead of using scripts means you'll need to fix any bug twice). If SHIFT is pressed, switch to DRAW SWORD state, which animates the sword-drawing animation. At the end of the animation, DRAW SWORD state changes to SWORD DRAWN state.

SWORD DRAWN state has the movement code again, but sets the sprite to the sword-drawn instead of the normal idle. Also, code that uses the sword for attacks should be only in this state. Also, if you RELEASE the shift key, this state would have code to sheathe it again (either by instantly changing to the normal idle state, or having a special animation state like the way we drew the sword).
 
Top