- Modifié
Seeking advice on best practices
Hi it's been a long time since I have used spine and I can see a lot has changed. Most notably seems to be the introduction of TrackEntry's. I had a look at the docs but I would just like confirmation on if there are any other ways this could be done:
Setting animations - looks like you still use SetAnimation, but I noticed you can now use track entry's instead of a string. For track entrys, should I just be getting the list and do string comparisons to find out what animation each one has and caching it in a dictionary? Or is there a way I can do this pre-runtime and have it hooked up into the inspector or something?
Attachments - I have a a few attachments that I would like to show/hide on demand in code. I saw something about skins being a recommended way to do this but for now I have just been using setattachment to null/attachment to do it. I'm not using an equipment system or anything this is just more of a general edge case I'm guessing I can either run a seperate track of animations for it, use skins or use setattachment, which would you recommend?
For setting animations, you can specify a string or animation (as it has always been). You can't specify a track entry, instead AnimationState setAnimation
and AnimationState addAnimation
return a TrackEntry which you can configure.
Using Skeleton setAttachment
or Slot attachment
are fine ways to set or hide an attachment for a slot. You may need to do this every frame (it is very cheap, it just sets a field) if your animations key the attachment for the slot and you want to override the animations.
I see, seems I misread the trackentry stuff. Thank's for clarification. A few more questions if you don't mind Nate, it's just very reassuring.
Glad to hear that setAttachment is cheap, I actually assumed it would be a bit more expensive.
-For setting animations, I would assume it's more optimal to then specify the animation? Is there a way to get the references to them?
-Animation speed, I want to change the timescales on different animations for a character, each animation would have a different timescale that would not change. It seems like I should be setting the timescale on the trackentry every time I set an animation right?
-Kind of following on. I thought I read that a track entry is disposed of after its animation is finished. So if I would like to fire an event every time a particular animation finishes, I should be assigning an oncomplete event every time I set that particular animation?
DanBrodie a écrit-For setting animations, I would assume it's more optimal to then specify the animation? Is there a way to get the references to them?
See SkeletonData findAnimation
.
DanBrodie a écritIt seems like I should be setting the timescale on the trackentry every time I set an animation right?
Yep.
DanBrodie a écritI thought I read that a track entry is disposed of after its animation is finished.
See AnimationState setAnimation
:
loop If true, the animation will repeat. If false it will not, instead its last frame is applied if played beyond its duration. In either case TrackEntry
trackEnd
determines when the track is cleared.
So, you can set TrackEntry trackEnd
to control when the animation stops being applied (or queue an animation with addAnimation
).
DanBrodie a écritif I would like to fire an event every time a particular animation finishes, I should be assigning an oncomplete event every time I set that particular animation?
That is one way to do it, yes. Another is to use AnimationStateListener end
, which will be fired even if the animation is interrupted.