mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-06-05 22:02:54 +00:00
Updated idle animation to use 2 sprites instead of just 1.
This commit is contained in:
parent
c973030d9d
commit
3687ff2c21
@ -25,14 +25,18 @@ fun AnimatedSpriteImage(
|
|||||||
// Start the animation when the component is first created
|
// Start the animation when the component is first created
|
||||||
LaunchedEffect(characterId) {
|
LaunchedEffect(characterId) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
animationStateMachine.playAnimation(DigimonAnimationType.IDLE)
|
animationStateMachine.playIdleAnimation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change animation when animationType changes
|
// Change animation when animationType changes
|
||||||
LaunchedEffect(animationType) {
|
LaunchedEffect(animationType) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
animationStateMachine.playAnimation(animationType)
|
if (animationType == DigimonAnimationType.IDLE) {
|
||||||
|
animationStateMachine.playIdleAnimation()
|
||||||
|
} else {
|
||||||
|
animationStateMachine.playAnimation(animationType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -168,6 +168,40 @@ class DigimonAnimationStateMachine(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special method for idle animation that cycles between IDLE and IDLE2
|
||||||
|
suspend fun playIdleAnimation() {
|
||||||
|
if (currentAnimation == DigimonAnimationType.IDLE && isPlaying) {
|
||||||
|
return // Already playing idle animation
|
||||||
|
}
|
||||||
|
|
||||||
|
currentAnimation = DigimonAnimationType.IDLE
|
||||||
|
isPlaying = true
|
||||||
|
|
||||||
|
// Get both IDLE and IDLE2 frames
|
||||||
|
val idleFrames = spriteFileMappings[DigimonAnimationType.IDLE] ?: listOf("00")
|
||||||
|
val idle2Frames = spriteFileMappings[DigimonAnimationType.IDLE2] ?: listOf("01")
|
||||||
|
|
||||||
|
// Combine frames for cycling idle animation
|
||||||
|
val combinedFrames = (idleFrames + idle2Frames).distinct()
|
||||||
|
|
||||||
|
if (combinedFrames.isEmpty()) {
|
||||||
|
println("Warning: No idle sprite files found")
|
||||||
|
currentSpriteIndex = 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val duration = animationDurations[DigimonAnimationType.IDLE] ?: 500L
|
||||||
|
|
||||||
|
// Cycle through idle frames
|
||||||
|
var frameIndex = 0
|
||||||
|
while (isPlaying && currentAnimation == DigimonAnimationType.IDLE) {
|
||||||
|
val spriteIndex = combinedFrames[frameIndex % combinedFrames.size]
|
||||||
|
currentSpriteIndex = spriteIndex.toIntOrNull() ?: 0
|
||||||
|
delay(duration)
|
||||||
|
frameIndex++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun stopAnimation() {
|
fun stopAnimation() {
|
||||||
isPlaying = false
|
isPlaying = false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user