Legacy GM Is it possible to access the animation of a sprite exported from Spine?

wilmer

Member
Greetings to everyone in the community
Look, I need help in this, I make my animations with Spine, I export them and I post them as a single sprite in GMS, and I would like to know if I can use sprite_index, to call both that sprite and its different animations; if the main functions to call its animation are skeleton_animation_set and skeleton_animation_get () or draw_skeleton, which I can not use with sprite_index.

Example:
Whether in a Step, Create or Script event, use:
Code:
// animation to be still
sprite_index = spr_character

// animation to be dead
sprite_index = spr_character

// animation to be attacking
sprite_index = spr_character
 

rIKmAN

Member
Greetings to everyone in the community
Look, I need help in this, I make my animations with Spine, I export them and I post them as a single sprite in GMS, and I would like to know if I can use sprite_index, to call both that sprite and its different animations; if the main functions to call its animation are skeleton_animation_set and skeleton_animation_get () or draw_skeleton, which I can not use with sprite_index.

Example:
Whether in a Step, Create or Script event, use:
Code:
// animation to be still
sprite_index = spr_character

// animation to be dead
sprite_index = spr_character

// animation to be attacking
sprite_index = spr_character
When you load Spine json files into the IDE they appear like any other sprite in the resource tree which you can then assign as the sprite_index of an object like you would with any other sprite.

Changing the sprite_index of that object to another Spine sprite would assign another skeleton file to that sprite, and to use the animation data from a Spine sprite you use the skeletal animation functions to get/set data within the skeleton.

Have you exported from Spine as json files or as images?

You need to be using json files to be able to access the skeletal animation data from the Spine file to allow you to change animations, attachments etc as if you are just using images exported from Spine then they are no different than a normal sprite and obviously don’t contain any skeletal animation data.
 

wilmer

Member
Hello rIKmAN, I export from spine in json format, what I would like to know is for example you, how would you do this correctly.

sprite_index = skeleton_animation_set ("idle")

sprite_index = skeleton_animation_set ("walking")

Do I make myself clear?
 
C

CreatorAtNight

Guest
If you import the JSON file in the sprite editor, you can set the spine animations with:
Code:
skeleton_animation_set("animationName");
To set the sprite on the object itself you do:
Code:
sprite_index = spr_sprite //Just the name of the sprite in the Game Maker sprite tree
 

rIKmAN

Member
@wilmer
Just like CreatorAtNight explained you need to set the Spine sprite as the active sprite on an object either via code or by using the IDE so assign the sprite to the object.

Then in the objects events you can use the skeletal animation functions to interact with the skeleton.
Which event you use will depend on what you are trying to do - I recommend checking out the manual pages for the skeletal animation functions.

If you had an animation in Spine called "walk", then to set the skeleton to this animation as soon as the object was created you would add this code into the Create Event of the object with the Spine sprite attached to it.

Code:
skeleton_animation_set("walk");
If you wanted it to start walking when you pressed a key then you place it inside checks for keypresses or gamepad input etc.

Always remember to check whether the animation is already playing before setting it, as otherwise you will see no animation as the skeleton will be being reset to the first frame each step.

Hope that helps.
 
Last edited:
Top