• 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 Animation Single Loop

K

Kdkreig

Guest
I'm currently experimenting with GMS2 and I'm essentially doing that with the SNES Link to the Past sprites. I have movement and I can make Link swing his sword. The main problem is that I can't find a way that I understand that makes it so that his sword swing animation happens only once and returns him back to the standing sprite and not that swinging sprite animation.

This is all the code that makes Link work
Code:
//movement
if (keyboard_check(vk_down))
    {
        y += 4;
        sprite_index = spr_Link_WalkDown;
    }
if (keyboard_check(vk_up))
    {
        y -= 4;
        sprite_index = spr_Link_WalkUp;
    }
if (keyboard_check(vk_left))
    {
        x -= 4;
        sprite_index = spr_Link_WalkLeft;
    }
if(keyboard_check(vk_right))
    {
        x += 4;
        sprite_index = spr_Link_WalkRight;
    }
if(keyboard_check_released(vk_right)) sprite_index = spr_Link_StandRight;
if(keyboard_check_released(vk_up)) sprite_index = spr_Link_StandUp;
if(keyboard_check_released(vk_left)) sprite_index = spr_Link_StandLeft;
if(keyboard_check_released(vk_down)) sprite_index = spr_Link_StandDown;

//attack animations
if(keyboard_check(vk_space)) && (sprite_index = spr_Link_StandDown)
    {
        sprite_index = spr_Link_SwordSwingDown;
    }


//if(keyboard_check_released(vk_space) && sprite_index = spr_Link_SwordSwingDown) sprite_index = spr_Link_StandDown;
//if(keyboard_check(vk_space) && sprite_index = spr_Link_StandLeft) sprite_index = spr_Link_SwordSwingLeft;
//if(keyboard_check_released(vk_space) && sprite_index = spr_Link_SwordSwingLeft) sprite_index = spr_Link_StandLeft;
The code should be mostly organized. The commented code is just so that I can work on one piece at a time and not worry about other stuff possibly breaking. If it was unclear above then here. I'm currently trying to get it so that when I push space bar the attack animation does 1 loop and stops then returns link back to his standing position.
 

rIKmAN

Member
Use the Animation End Event (which fires when an animation ends) to detect the current animation (which has just ended) and set the sprite back to the idle animation.

You can add checks in here to see if the space bar is being held down to do another sword swing if it is, or back to idle if not (or whatever you want etc).
 
K

Kdkreig

Guest
Use the Animation End Event (which fires when an animation ends) to detect the current animation (which has just ended) and set the sprite back to the idle animation.
You can add checks in here to see if the space bar is being held down to do another sword swing if it is, or back to idle if not (or whatever you want).
I can't seem to find the Animation End Event you are referencing. Could you make an example of the code you are inferring? or even better use it as an example in my code as a possible fix.
 

hippyman

Member
I can't seem to find the Animation End Event you are referencing. Could you make an example of the code you are inferring? or even better use it as an example in my code as a possible fix.
It's one of those special events hidden away in the "other" section that a lot of people seem to miss.
 
K

Kdkreig

Guest
It's one of those special events hidden away in the "other" section that a lot of people seem to miss.
Ok, where can one find this "other" section you are speaking of? A vague sentence like that doesn't help anyone that doesn't know where that is at.
Please explain better.
 

rIKmAN

Member
I can't seem to find the Animation End Event you are referencing. Could you make an example of the code you are inferring? or even better use it as an example in my code as a possible fix.
Ok, where can one find this "other" section you are speaking of? A vague sentence like that doesn't help anyone that doesn't know where that is at.
Please explain better.
Well you've been told it's an "event", and I assume if you have got this far you know how to add an event to an object?
Putting 2 and 2 together you can probably work out to look in the "Other" section when you add a new event to find "Animation End", no?

In case that wasn't clear - the Animation End Event is listed under "Other" when you create a new event.

I usually use state machines and switch statements to manage stuff like this, but a simple example to give you an idea using your own code above for the sword swing example would be:
Code:
// if the sword swinging sprite has finished it's animation
if(sprite_index == spr_Link_SwordSwingDown)
{
    // set it back to idle
    sprite_index = spr_Link_StandDown;
}
You can then add checks for inputs to branch to other animations if certain keys are pressed or held at the end of a certain animation etc, for example if space is being held when it ends you can do another sword swipe.

As I said I would recommend a state machine and switch statements for something like this as using if checks all over the place just gets messy really quick, so this example is just to give you an idea of how you can use the Animation End Event to switch sprite based on what you want to do at the end of an animation, and from there you can build on it.
 

hippyman

Member
Ok, where can one find this "other" section you are speaking of? A vague sentence like that doesn't help anyone that doesn't know where that is at.
Please explain better.
This right here shows that you're putting almost zero effort into this yourself.
 
K

Kdkreig

Guest
This right here shows that you're putting almost zero effort into this yourself.
I found it now. Maybe saying "go to event window" would help a bit. I'm still learning the location of things in this program. Please don't assume that people know every aspect of the program. I downloaded this thing not 2-3 days ago and i learned most of what i typed in 20-30 minutes. I appreciate the help though.


Well you've been told it's an "event", and I assume if you have got this far you know how to add an event to an object?
Putting 2 and 2 together you can probably work out to look in the "Other" section when you add a new event to find "Animation End", no?

In case that wasn't clear - the Animation End Event is listed under "Other" when you create a new event.

I usually use state machines and switch statements to manage stuff like this, but a simple example to give you an idea using your own code above for the sword swing example would be:
Code:
// if the sword swinging sprite has finished it's animation
if(sprite_index == spr_Link_SwordSwingDown)
{
    // set it back to idle
    sprite_index = spr_Link_StandDown;
}
You can then add checks for inputs to branch to other animations if certain keys are pressed or held at the end of a certain animation etc, for example if space is being held when it ends you can do another sword swipe.

As I said I would recommend a state machine and switch statements for something like this as using if checks all over the place just gets messy really quick, so this example is just to give you an idea of how you can use the Animation End Event to switch sprite based on what you want to do at the end of an animation, and from there you can build on it.
Thank you. I found what you were saying there. The code worked and I thank you good sir.
 

rIKmAN

Member
I found it now. Maybe saying "go to event window" would help a bit. I'm still learning the location of things in this program. Please don't assume that people know every aspect of the program. I downloaded this thing not 2-3 days ago and i learned most of what i typed in 20-30 minutes. I appreciate the help though.

Thank you. I found what you were saying there. The code worked and I thank you good sir.
No problem.

I would highly recommend you read through the manual like it was a book at least once - even if just skimming things you don't really understand yet.
Later on when you want to add something, you will remember "ah I read something about that" and be able to go and look it up in the manual / use the search function.

It's full of great information and will answer 90% of your questions as a beginner, and more importantly plant seeds in your mind when you start to get the hang of the basics and want to add feature x/y/z and are wondering how to do it.

Good luck with your learning, and welcome to the community!
 
K

Kdkreig

Guest
No problem.

I would highly recommend you read through the manual like it was a book at least once - even if just skimming things you don't really understand yet.
Later on when you want to add something, you will remember "ah I read something about that" and be able to go and look it up in the manual / use the search function.

It's full of great information and will answer 90% of your questions as a beginner, and more importantly plant seeds in your mind when you start to get the hang of the basics and want to add feature x/y/z and are wondering how to do it.

Good luck with your learning, and welcome to the community!
Thanks, I might just scrim through it later on.
I'm more amazed that I couldn't find anything online about it. No videos, no posts on here, nothing. Thanks once again.
 
Top