changeset 753:eb5ae1f1bc87

fix: do not apply last frame value after animation has stopped
author Sam <sam@basx.dev>
date Tue, 20 Jun 2023 00:30:58 +0700
parents bcd246da025d
children 5df644a3b6b8
files src/semicongine/animation.nim src/semicongine/core/matrix.nim src/semicongine/scene.nim
diffstat 3 files changed, 4 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/animation.nim	Mon Jun 19 01:14:58 2023 +0700
+++ b/src/semicongine/animation.nim	Tue Jun 20 00:30:58 2023 +0700
@@ -36,7 +36,7 @@
   AnimationPlayer*[T] = object
     animation*: Animation[T]
     currentTime: float32
-    playing: bool
+    playing*: bool
     currentDirection: int
     currentIteration: int
     currentValue*: T
--- a/src/semicongine/core/matrix.nim	Mon Jun 19 01:14:58 2023 +0700
+++ b/src/semicongine/core/matrix.nim	Tue Jun 20 00:30:58 2023 +0700
@@ -117,7 +117,7 @@
     maxwidth = 0
 
   for n in value.data:
-    let strval = $n
+    let strval = &"{n:.2}"
     strvalues.add(strval)
     if strval.len > maxwidth:
       maxwidth = strval.len
--- a/src/semicongine/scene.nim	Mon Jun 19 01:14:58 2023 +0700
+++ b/src/semicongine/scene.nim	Tue Jun 20 00:30:58 2023 +0700
@@ -51,14 +51,11 @@
 func update*(animation: var EntityAnimation, dt: float32) =
   animation.player.advance(dt)
 
-func getValue*(animation: var EntityAnimation): Mat4 =
-  return animation.player.currentValue
-
 func transform*(entity: Entity): Mat4 =
   result = entity.internal_transform
   for component in entity.components.mitems:
-    if component of EntityAnimation:
-      result = result * EntityAnimation(component).getValue
+    if component of EntityAnimation and EntityAnimation(component).player.playing:
+      result = result * EntityAnimation(component).player.currentValue
 
 func originalTransform*(entity: Entity): Mat4 =
   entity.internal_transform