generateFrameNumbers and generateFrameNames updated

They both now take  a frames property in the config which allows you to define the sequence of frames in the animation, rather than just sequentially as before.
This commit is contained in:
Richard Davey 2017-08-01 21:56:17 +01:00
parent 24278c6f3b
commit c7200108e8
3 changed files with 60 additions and 23 deletions

View file

@ -8,12 +8,8 @@ var GenerateFrameNames = function (key, config)
var end = GetValue(config, 'end', 0);
var suffix = GetValue(config, 'suffix', '');
var zeroPad = GetValue(config, 'zeroPad', 0);
var out = GetValue(config, 'framesArray', []);
var diff = (start < end) ? 1 : -1;
// Adjust because we use i !== end in the for loop
end += diff;
var out = GetValue(config, 'outputArray', []);
var frames = GetValue(config, 'frames', false);
var texture = this.textureManager.get(key);
@ -22,15 +18,39 @@ var GenerateFrameNames = function (key, config)
return out;
}
for (var i = start; i !== end; i += diff)
var diff = (start < end) ? 1 : -1;
// Adjust because we use i !== end in the for loop
end += diff;
var i;
var frame;
// Have they provided their own custom frame sequence array?
if (Array.isArray(frames))
{
var frame = prefix + Pad(i, zeroPad, '0', 1) + suffix;
for (i = 0; i < frames.length; i++)
{
frame = prefix + Pad(frames[i], zeroPad, '0', 1) + suffix;
if (texture.has(frame))
{
out.push({ key: key, frame: frame });
}
}
}
else
{
for (i = start; i !== end; i += diff)
{
frame = prefix + Pad(i, zeroPad, '0', 1) + suffix;
if (texture.has(frame))
{
out.push({ key: key, frame: frame });
}
}
}
return out;
};

View file

@ -5,7 +5,8 @@ var GenerateFrameNumbers = function (key, config)
var startFrame = GetValue(config, 'start', 0);
var endFrame = GetValue(config, 'end', -1);
var firstFrame = GetValue(config, 'first', false);
var out = GetValue(config, 'framesArray', []);
var out = GetValue(config, 'outputArray', []);
var frames = GetValue(config, 'frames', false);
var texture = this.textureManager.get(key);
@ -14,6 +15,26 @@ var GenerateFrameNumbers = function (key, config)
return out;
}
if (firstFrame && texture.has(firstFrame))
{
out.push({ key: key, frame: firstFrame });
}
var i;
// Have they provided their own custom frame sequence array?
if (Array.isArray(frames))
{
for (i = 0; i < frames.length; i++)
{
if (texture.has(frames[i]))
{
out.push({ key: key, frame: frames[i] });
}
}
}
else
{
// No endFrame then see if we can get it
if (endFrame === -1)
@ -21,18 +42,14 @@ var GenerateFrameNumbers = function (key, config)
endFrame = texture.frameTotal;
}
if (firstFrame && texture.has(firstFrame))
{
out.push({ key: key, frame: firstFrame });
}
for (var i = startFrame; i <= endFrame; i++)
for (i = startFrame; i <= endFrame; i++)
{
if (texture.has(i))
{
out.push({ key: key, frame: i });
}
}
}
return out;
};

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: 'e6190010-76d1-11e7-bdd9-f146bb3b0102'
build: 'a2b2b8a0-76fb-11e7-8281-5f266fa7c1f9'
};
module.exports = CHECKSUM;