pixelmeat

Hello again!

Self explanatory subject here, I'm trying to access the current animation frame. I know it may be the simplest thing to do, but I don't know how. Halp?
I use c# for scripting and it would also be great if someone told me where to find an api or just a list of all the Spine runtime functions and their descriptions.

Cheers!
Avatar
pixelmeat
  • Postovi: 50

Pharan

float currentTime = 0f;
int currentFrame = 0;

var currentTrack = mySkeletonAnimation.state.GetCurrent(0); // May be null if no animation is playing.
if (currentTrack != null) {
currentTime = currentTrack.time;
currentFrame = currentTime / 30f; // convert seconds to Spine editor dopesheet "frames". Spine doesn't actually use frames.
}
Avatar
Pharan
  • Postovi: 5366

pixelmeat

Thank you!

Any hint about Spine functions documentation?

-- 13 Nov 2015, 09:48 --

Just some corrections to Pharan code here:
var currentTrack = skeletonAnimation.state.GetCurrent(0); // May be null if no animation is playing.

if (currentTrack != null)
{
currentTime = currentTrack.time;
currentFrame = Mathf.RoundToInt(currentTime * 30f); // convert seconds to Spine editor dopesheet "frames". Spine doesn't actually use frames.
if (currentFrame >= 3) startJump = true; //Here you can trigger things using currentFrame. Be aware that this is not precise, as the exact frame you aim for may have passed by the time you check it, thus the ">=".
}
I hope someone finds this useful :)
Avatar
pixelmeat
  • Postovi: 50

Pharan

If you just wanted something to happen at a certain time, you could have used Spine Events.
http://esotericsoftware.com/spine-events.
Much cleaner.
Avatar
Pharan
  • Postovi: 5366

pixelmeat

I just saw your answer. I will check events asap, as they could be a great help for triggering hits in my game.
Thanks Pharan!
Avatar
pixelmeat
  • Postovi: 50

Pharan

You can find a sample of C# event syntax here: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-unity/Assets/Examples/Scripts/BasicPlatformerController.cs#L81
This is the script from the sample BasicPlatformerController scene.
Avatar
Pharan
  • Postovi: 5366


Natrag na Unity