Skip to content

Commit e4787c0

Browse files
Merge branch 'fix-spriteanimation' into 'master'
[FIX] fix animation when duration is changed See merge request codingame/game-engine!244
2 parents 82b5b93 + 665773b commit e4787c0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

engine/modules/entities/src/main/resources/view/entity-module/SpriteAnimation.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class SpriteAnimation extends TextureBasedEntity {
1414
duration: 1000,
1515
playing: true,
1616
restarted: null,
17-
animationProgressTime: 0,
17+
animationProgress: 0,
1818
date: 0
1919
})
2020
}
@@ -35,12 +35,10 @@ export class SpriteAnimation extends TextureBasedEntity {
3535
super.updateDisplay(state, changed, globalData)
3636

3737
if (state.images) {
38-
const duration = state.duration
3938
const images = state.images.split(',')
4039

41-
const animationProgress = (state.loop ? unlerpUnclamped : unlerp)(0, duration, state.animationProgressTime)
42-
if (animationProgress >= 0) {
43-
const animationIndex = Math.floor(images.length * animationProgress)
40+
if (state.animationProgress >= 0) {
41+
const animationIndex = Math.floor(images.length * state.animationProgress)
4442
const image = state.loop ? images[animationIndex % images.length] : (images[animationIndex] || images[images.length - 1])
4543
try {
4644
this.graphics.texture = PIXI.Texture.fromFrame(image)
@@ -55,11 +53,11 @@ export class SpriteAnimation extends TextureBasedEntity {
5553

5654
computeAnimationProgressTime (prevState, currState) {
5755
if (currState.restarted && currState.restarted.date === currState.date) {
58-
currState.animationProgressTime = 0
56+
currState.animationProgress = 0
5957
} else {
60-
currState.animationProgressTime = prevState.animationProgressTime
58+
currState.animationProgress = prevState.animationProgress
6159
if (prevState.playing) {
62-
currState.animationProgressTime += currState.date - prevState.date
60+
currState.animationProgress += (currState.date - prevState.date) / prevState.duration
6361
}
6462
}
6563
}

playground/misc/misc-3-release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The CodinGame SDK is regularly updated and improved. This document lets you know what changed in the latest releases.
44

5+
## 3.8.3
6+
7+
### 🐞 Bug fix
8+
9+
- SpriteAnimation: fix wrong current frame when the animation duration is changed
10+
511
## 3.8.2
612

713
### 🐞 Bug fix

0 commit comments

Comments
 (0)