GameMaker Spine 2D Animations Not Changing

So I'm trying to use Spine 2D to get my characters looking more alive and I've come up against an issue early on.

I have 2 animations to start

-idle
-idleback

GM2 will let me change from idle to idleback but won't change back to idle.

Here is the create code:
Code:
skeleton_skin_set("Brian");

skeleton_animation_mix("idle","idleback",.03);
skeleton_animation_mix("idleback","idle",.03);
skeleton_animation_set("idle");
here is the alarm:
Code:
if dir=1{
    dir=0;
    skeleton_animation_set("idleback");
}else{
    dir=1;
    skeleton_animation_set("idle");
}
I used draw_text to confirm the "dir" value is changing and the skeleton_animation_get() displays the right animation but, for some reason, it's just not changing.

I really want to use skeleton_animation_mix() but that doesn't work at all.

Any advice would be super awesome! I'd rather not have to export a bajillion pngs and build a system to animation them if I can help it. :)
 
Last edited:

rIKmAN

Member
So I'm trying to use Spine 2D to get my characters looking more alive and I've come up against an issue early on.

I have 2 animations to start

-idle
-idleback

GM2 will let me change from idle to idleback but won't change back to idle.

Here is the create code:
Code:
skeleton_skin_set("Brian");

skeleton_animation_mix("idle","idleback",.03);
skeleton_animation_mix("idleback","idle",.03);
skeleton_animation_set("idle");
here is the step:
Code:
if dir=1{
    dir=0;
    skeleton_animation_set("idleback");
}else{
    dir=1;
    skeleton_animation_set("idle");
}
I used draw_text to confirm the "dir" value is changing and the skeleton_animation_get() displays the right animation but, for some reason, it's just not changing.

I really want to use skeleton_animation_mix() but that doesn't work at all.

Any advice would be super awesome! I'd rather not have to export a bajillion pngs and build a system to animation them if I can help it. :)
If that's the actual code then you are setting the animation every single frame to either "idle" or "idleback".
Setting the animation resets the animation to frame 1 (image_index of 0) and doing this every step will make it appear like it doesn't move because it's always being reset.
 
Sorry, I should have been more clear. It wasn't in the step. It's on an alarm. So it only runs the code at the end of the animation cycle.

*Edited to specify it's an alarm, not a step.
 

rIKmAN

Member
Sorry, I should have been more clear. It wasn't in the step. It's on an alarm. So it only runs the code at the end of the animation cycle.

*Edited to specify it's an alarm, not a step.
How are you setting the length of the alarm to ensure it only runs once the animation has finished it's cycle?
The code you've posted doesn't show you setting the alarm at all, which is possibly why it doesn't work because that code never gets run if the alarm doesn't fire.

Add some show_debug_messages() in your code and you can easily test this.

It sounds like the Animation End Event is more suitable for your needs as this is exactly what it's for.
 
The animation loops perfectly when the alarm is set to 80. According to the draw_text it's changing the skeleton_animation. It also changes successfully the first run but then won't go back. I'll just use PNGs. There doesn't seem to be enough documentation on these behaviors or tutorials that I'm able to discern the right way to set these up. Even the tuts I followed to the letter don't work. Oh well. The hard way it is! :)
 

rIKmAN

Member
The animation loops perfectly when the alarm is set to 80. According to the draw_text it's changing the skeleton_animation. It also changes successfully the first run but then won't go back. I'll just use PNGs. There doesn't seem to be enough documentation on these behaviors or tutorials that I'm able to discern the right way to set these up. Even the tuts I followed to the letter don't work. Oh well. The hard way it is! :)
That's generally not a good way to do it, because if you decide later to go in and change the animation in Spine or tweak it and it becomes a bit longer or shorter you are going to have to go through your code change values for the alarm until you get it right again.

Use the Animation End Event, that's what it's for and it will always fire at the end of the current animation, no matter what length you may change to later.

If you want to export your project "as-is" to a yyz and host it somewhere I'll edit the project to change animations and send it back to you so you have an example to go off and build on.
 
Is there a tutorial somewhere you could point to? I'd like to do it myself so the knowledge gets cemented in.

It's just confusing because none of the spine/GM tuts mention anything other than create and step.
 

rIKmAN

Member
Other than the official YYG Blog Article and whatever videos you can find on Youtube - not that I know of.
I did consider doing some myself a while back but it didn't appear like there were too many people using GMS and Spine together to make it worth the time needed to create them.

From what you've posted it looks like you are just trying to change between 2 animations: once one ends play the next, when that ends, play the first again etc etc
Is that correct?

If so then set the skeleton to play the first animation in the Create Event.
Add an Animation End Event - in here you want to check what the current animation is (this will be the animation that has just ended) and based on that you can then set the skeleton to the new animation.

So that means at the end of each animations cycle it will be reset to the other animation and it will do this repeatedly on a loop because the Animation End Event will fire at the end of every animation cycle regardless of the animation or the length of it.

I use a switch as it makes it easier to add more states / transitions later, but something like this:
Code:
switch(skeleton_animation_get())
{
    case "idle":
        skeleton_animation_set("idleback");
        break;

    case "idleback":
        skeleton_animation_set("idle");
        break;
}
You don't need anything in the Step event or any alarms to get this working - just a Create Event and an Animation End Event.
 
Last edited:
So yeah, same issue. It will switch to the second animation but it will not switch back.

The value of skeleton_animation_get() changes back and forth but it just loops the second animation. And skeleton_animation_mix() does nothing at all.
 

rIKmAN

Member
So yeah, same issue. It will switch to the second animation but it will not switch back.

The value of skeleton_animation_get() changes back and forth but it just loops the second animation. And skeleton_animation_mix() does nothing at all.
If you are using similar code as I posted above but it isn't working as I explained, and you are 100% sure there are no errors in your code (typos, logic errors, using the wrong animation name etc) then the issue might be with your Spine skeleton.

What version of GMS are you using?
What version of Spine are you using?
Do the animations have keys set at the start and end of the animations in Spine?
Are the animations different enough that you can easily tell the difference between them visually when they are playing?

Mixing will make 2 animations smoothly transition into each other, rather than "snapping" from one to the other.
Until you get the basics of animation changes working I would just remove those lines for now to narrow down and help pinpoint your issue.
 
I'll start over in spine from square 1. There is no code error at all. Not enough code as I made this new object to test spine out. Seems I got everything wrong in spine.

Thanks for the help.

Learned something new and useful! :)
 

rIKmAN

Member
I'll start over in spine from square 1. There is no code error at all. Not enough code as I made this new object to test spine out. Seems I got everything wrong in spine.

Thanks for the help.

Learned something new and useful! :)
Make it as simple as possible - a square sprite with 1 animation moving left to right and one moving up and down.
Once you've got that working you can transfer that code / learned knowledge over to your more complex project and skeleton.
 
Got it working finally thanks to you!

Now I just need to create transition animations since skelton_animation_mix() won't work in animation end. Shouldn't be too tough though.

Thanks again!
 
Top