From a8a7d459561c1416278ca87ce999b31ea2576c5c Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 3 Jul 2019 15:07:53 +0100 Subject: [PATCH] Removing a frame from a 2 frame animation would cause an error when a Sprite using that animation next tried to render. Fix #4621 --- CHANGELOG.md | 1 + src/animations/Animation.js | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db192182d..a9f905304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ * `Tilemap.createFromObjects` would ignore the `scene` argument passed in to the method. It's now used (thanks @samme) * Fixed a bug in the WebGL and Canvas Renderers where a Sprite with a `flipX` or `flipY` value set would render the offset frames slightly out of place, causing the animation to appear jittery. Also, the sprite would be out of place by its origin. Fix #4636 #3813 (thanks @jronn @B3L7) * Animations with custom pivots, like those created in Texture Packer with the pivot option enabled, would be mis-aligned if flipped. They now render in the correct position, regardless of scale or flip on either axis. Fix #4155 (thanks @Zax37) +* Removing a frame from a 2 frame animation would cause an error when a Sprite using that animation next tried to render. Fix #4621 (thanks @orlicgms) ### Examples, Documentation and TypeScript diff --git a/src/animations/Animation.js b/src/animations/Animation.js index 6d892db9a..d2c0fb883 100644 --- a/src/animations/Animation.js +++ b/src/animations/Animation.js @@ -843,9 +843,11 @@ var Animation = new Class({ var len = this.frames.length; var slice = 1 / (len - 1); + var frame; + for (var i = 0; i < len; i++) { - var frame = this.frames[i]; + frame = this.frames[i]; frame.index = i + 1; frame.isFirst = false; @@ -855,11 +857,21 @@ var Animation = new Class({ if (i === 0) { frame.isFirst = true; - frame.isLast = (len === 1); - frame.prevFrame = this.frames[len - 1]; - frame.nextFrame = this.frames[i + 1]; + + if (len === 1) + { + frame.isLast = true; + frame.nextFrame = frame; + frame.prevFrame = frame; + } + else + { + frame.isLast = false; + frame.prevFrame = this.frames[len - 1]; + frame.nextFrame = this.frames[i + 1]; + } } - else if (i === len - 1) + else if (i === len - 1 && len > 1) { frame.isLast = true; frame.prevFrame = this.frames[len - 2];