All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ru.casperix.spine.AnimationState.kt Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
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)
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy