Updated idle animation to use 2 sprites instead of just 1.

This commit is contained in:
lightheel 2025-08-04 13:26:39 -04:00
parent c973030d9d
commit 3687ff2c21
2 changed files with 40 additions and 2 deletions

View File

@ -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)
}
} }
} }

View File

@ -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
} }