From 0b270151ffcdc56d01d872c24c61094fdfcf9982 Mon Sep 17 00:00:00 2001 From: Shaun Date: Tue, 7 Apr 2020 19:35:56 +0200 Subject: [PATCH] fixes #1450 --- src/client/js/components/animation.js | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/client/js/components/animation.js b/src/client/js/components/animation.js index 79ab3671..9bb610c3 100644 --- a/src/client/js/components/animation.js +++ b/src/client/js/components/animation.js @@ -21,21 +21,27 @@ define([ frameDelayCd: 0, + oldSheetName: null, + oldCell: null, oldTexture: null, init: function (blueprint) { - if (!this.obj.sprite) + const { template, frameDelay, obj: { sheetName, cell, sprite } } = this; + + if (!sprite) return true; - this.oldTexture = this.obj.sprite.texture; + this.oldSheetName = sheetName; + this.oldCell = cell; + this.oldTexture = sprite.texture; this.frame = 0; this.frameDelayCd = 0; - for (let p in this.template) - this[p] = this.template[p]; + for (let p in template) + this[p] = template[p]; - this.frameDelayCd = this.frameDelay; + this.frameDelayCd = frameDelay; this.setSprite(); }, @@ -68,7 +74,21 @@ define([ }, destroy: function () { - this.obj.sprite.texture = this.oldTexture; + const { oldSheetName, oldCell, oldTexture, obj: { sheetName, cell, sprite } } = this; + + //Make sure something didn't happen while we were in animation form + // that made us change sprite + if (oldSheetName === sheetName && oldCell === cell) { + sprite.texture = oldTexture; + + return; + } + + renderer.setSprite({ + sprite, + cell, + sheetName + }); } }; });