commonMain.ru.casperix.spine.AnimationState.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spine-jvm Show documentation
Show all versions of spine-jvm Show documentation
Signals for all occasions
package ru.casperix.spine
import ru.casperix.spine.animation.Animation
import ru.casperix.spine.animation.AnimationContext
class AnimationState( var animation: Animation? = null) {
var time: Float = 0f
fun nextFrame(skeleton: Skeleton, tickInSec: Float) {
val lastTime = time
time += tickInSec
val animation = animation ?: return
if (time > animation.duration) {
time -= animation.duration
}
applyAnimation(skeleton, animation, lastTime)
skeleton.updateWorldTransform()
}
private fun applyAnimation(skeleton:Skeleton, animation: Animation, lastTime: Float) {
val events = emptyList()
val alpha = 1f // For mixing between the current or setup pose (0) or the animation pose (1).
val blend = MixBlend.first // How the current or setup pose is mixed with the animation pose.
val direction = MixDirection.`in` // Whether mixing out to the setup pose or in to the animation pose.
val context = AnimationContext(skeleton, lastTime, time, events, alpha, blend, direction)
animation.timelines.forEach {
it.apply(context)
}
}
}