- Bearbeitet
Using multiple animations
Hi, I am in need of some advice with using multiple Spine animations, any help will be appreciated. I am using Game Maker.
I find this really hard to explain but I will try best I can.
How do I create multiple animations so that they can be played at the same time? For example I want an animation for my characters body, and then another animation for my characters one arm and gun, to be used for example for animating shots and gun recoil which needs to be run in Game Maker at runtime. However in both animations all bones are still there. So I can't just delete the unused bones in the 'arm and gun'-animation, because that will also delete those bones from the 'body' animation. But if I can't delete the bones the entire animation including all images will still be displayed in both animations. How do I make it so that only the arm and gun bones/images are shown in the 'arm and gun' animation, and only the other body parts are shown in the 'body' animation? I tried hiding the skin placeholders under the bones that I do not use in the arm and gun'-animation, but then those same hidden skin placeholders, and it's images, will also become hidden when running the 'body' animation. In Game Maker I have assigned 'body' animation to track 0 and 'arm and gun' to track 1.
I hope this makes sense as to what I am trying to do here, but maybe there is just some basic concept that I have missed in Spine?
You can apply two animations normaly to a skeleton as long as these animations do not share keyframes in the bones they are moving.
For example: Imagine your skeleton has two bones, BTop and BBottom. And you want to apply Animation1 and Animation2 to that skeleton at the same time.
If Animation1 has keyframes in BTop and BBottom, you won't be able to apply Animation2 to that skeleton at the same time.
If Animation1 only has keyframes in BTop and Animation2 only has keyframes in BBotton, You can play both at the same time.
It is a bit of a pain to be constantly checking in animations where and where not you have key frames so they can be mixed (there has to be always keyframes) or played at the same time (no keyframes), but you can get the hang of it.
That's strange I think, or am I still missing something obvious? If I plan to have many animations, like 20 different animations, or more, how on earth am I gonna avoid having some of the keyframes being shared by some of the animations? As a example, my shotgun recoil will animate differently than my pistol recoil, and the same with all my weapons, of which I plan to have a lot of (like 20 or more). With so many animations won't it be virtually impossible to prevent at least some of the same keyframes to be used by more than one animation?
What about the first keyframe 0, won't all animations need to use that at least?
EDIT: another issue I encounters with this method is that that my arm and gun bone is a child bone to my torso bone. This means that if I delete the keyframes for torso bone in the "arm and gun" animation, then the arm and gun bone does not move relative to the torso anymore, and I need it to do that.
Of course your animations will be different, but neither the shotgun recoil nor the gun recoil have to share a keyframe with the walking animation for example. That way you can play gunRecoil or shotgunRecoil together with the walking animation.
Also, for animations that are compounded that use some bone that also move in other animations I also use duplicated bone or control bones from time to time. These are extra bones that are only used in a particular animation to add some extra movement.
You have to understand that you have only one skeleton that play several animations simultaneously, not several skeletons that play different animations but are drawn together one on top of another.
If you want to have several skeletons one on top of another the best thing you could do is having 0 opacity in the slots you don't want to show or clearing the attachment for those specific slots.
Thank you Stringkiller for you help. I am in doubt about where I should place that extra control bone in the skeleton hierarchy?
Right now I have it so that all bones are parented by the torso bone:
Torso Bone
. - Arm and Gun Bone
. - Left Leg Bone
. - Right Leg Bone
. - Head Bone
. - etc.
Since the Arm and Gun bone have the Torso bone as parent, how do I make it so that it will only be parented to the controller bone (and not the Torso bone) when using the recoil animation?
You don't need a second hierarchy for what you want. Just create a recoil animation where you only set keys for the needed bones. Then at runtime you mix the walk animation with the recoil animation. Both animations will play at the same time even if you have keys set for the arm in your walk animation. You can take a look at https://github.com/EsotericSoftware/spine-superspineboy where we did exactly that although that particular example is a bit more advanced than what you might be after.
Thanks for the link and file Shiu. I am unsure whether Game Maker supports mixing several animations to be played at the same time independently of one another without using the concept of tracks (I have not been able to get an answer on the Game Maker forums community on this question). Do you know which Java source file contains the code for the animation mixing that you refer too?
https://github.com/EsotericSoftware/spi ... State.java
If GM gives you access to AnimationState you should be fine.