From dfb71fe2a6bd947cd14b459a05a8f046f145c4d0 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 8 Sep 2020 13:01:11 +0100 Subject: [PATCH] Fixes to GenerateFrameNumbers * `GenerateFrameNumbers` would include the __BASE frame by mistake in its calculations. This didn't end up in the final animation, but did cause a cache miss when building the animation. * `GenerateFrameNumbers` can now accept the `start` and `end` parameters in reverse order, meaning you can now do `{ start: 10, end: 1 }` to create the animation in reverse. --- src/animations/AnimationManager.js | 48 ++++++++++-------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/src/animations/AnimationManager.js b/src/animations/AnimationManager.js index 6bd6b401a..b2ea5ec8b 100644 --- a/src/animations/AnimationManager.js +++ b/src/animations/AnimationManager.js @@ -13,6 +13,7 @@ var GameEvents = require('../core/events'); var GetFastValue = require('../utils/object/GetFastValue'); var GetValue = require('../utils/object/GetValue'); var Pad = require('../utils/string/Pad'); +var NumberArray = require('../utils/array/NumberArray'); /** * @classdesc @@ -728,46 +729,29 @@ var AnimationManager = new Class({ out.push({ key: key, frame: firstFrame }); } - var i; + // No 'frames' array? Then calculate one automatically - // Have they provided their own custom frame sequence array? - if (Array.isArray(frames)) + if (!frames) { - for (i = 0; i < frames.length; i++) - { - if (texture.has(frames[i])) - { - out.push({ key: key, frame: frames[i] }); - } - else - { - console.warn('generateFrameNumbers: Frame ' + i + ' missing from texture: ' + key); - } - } - } - else - { - // No endFrame then see if we can get it if (endFrame === -1) { - endFrame = texture.frameTotal; + // -1 because of __BASE, which we don't want in our results + // and -1 because frames are zero based + endFrame = texture.frameTotal - 2; } - var diff = (startFrame < endFrame) ? 1 : -1; + frames = NumberArray(startFrame, endFrame); + } - // Adjust because we use i !== end in the for loop - endFrame += diff; - - for (i = startFrame; i !== endFrame; i += diff) + for (var i = 0; i < frames.length; i++) + { + if (texture.has(frames[i])) { - if (texture.has(i)) - { - out.push({ key: key, frame: i }); - } - else - { - console.warn('generateFrameNumbers: Frame ' + i + ' missing from texture: ' + key); - } + out.push({ key: key, frame: frames[i] }); + } + else + { + console.warn('generateFrameNumbers: Frame ' + i + ' missing from texture: ' + key); } }