mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Generate methods now take config objects.
This commit is contained in:
parent
baf69828a5
commit
59787a154f
1 changed files with 47 additions and 13 deletions
|
@ -7,6 +7,7 @@
|
|||
var Animation = require('./frame/Animation');
|
||||
var Map = require('../structs/Map');
|
||||
var Pad = require('../utils/string/Pad');
|
||||
var GetObjectValue = require('../utils/object/GetObjectValue');
|
||||
|
||||
/**
|
||||
* Animations are managed by the global AnimationManager. This is a singleton class that is
|
||||
|
@ -96,18 +97,38 @@ AnimationManager.prototype = {
|
|||
return child;
|
||||
},
|
||||
|
||||
generateFrameNumbers: function (key, startFrame, endFrame, firstFrame, out)
|
||||
generateFrameNumbers: function (key, config)
|
||||
{
|
||||
if (out === undefined) { out = []; }
|
||||
var startFrame = GetObjectValue(config, 'start', 0);
|
||||
var endFrame = GetObjectValue(config, 'end', -1);
|
||||
var firstFrame = GetObjectValue(config, 'first', false);
|
||||
var out = GetObjectValue(config, 'framesArray', []);
|
||||
|
||||
if (firstFrame)
|
||||
var texture = this.textureManager.get(key);
|
||||
|
||||
if (!texture)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
// No endFrame then see if we can get it
|
||||
|
||||
if (endFrame === -1)
|
||||
{
|
||||
endFrame = texture.frameTotal;
|
||||
}
|
||||
|
||||
if (firstFrame && texture.has(firstFrame))
|
||||
{
|
||||
out.push({ key: key, frame: firstFrame });
|
||||
}
|
||||
|
||||
for (var i = startFrame; i <= endFrame; i++)
|
||||
{
|
||||
out.push({ key: key, frame: i });
|
||||
if (texture.has(i))
|
||||
{
|
||||
out.push({ key: key, frame: i });
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
|
@ -127,22 +148,35 @@ AnimationManager.prototype = {
|
|||
* @param {number} [zeroPad=0] - The number of zeros to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4.
|
||||
* @return {string[]} An array of framenames.
|
||||
*/
|
||||
generateFrameNames: function (key, prefix, start, stop, suffix, zeroPad, out)
|
||||
generateFrameNames: function (key, config)
|
||||
{
|
||||
if (suffix === undefined) { suffix = ''; }
|
||||
if (zeroPad === undefined) { zeroPad = 0; }
|
||||
if (out === undefined) { out = []; }
|
||||
var prefix = GetObjectValue(config, 'prefix', '');
|
||||
var start = GetObjectValue(config, 'start', 0);
|
||||
var end = GetObjectValue(config, 'end', 0);
|
||||
var suffix = GetObjectValue(config, 'suffix', '');
|
||||
var zeroPad = GetObjectValue(config, 'zeroPad', 0);
|
||||
var out = GetObjectValue(config, 'framesArray', []);
|
||||
|
||||
var diff = (start < stop) ? 1 : -1;
|
||||
var diff = (start < end) ? 1 : -1;
|
||||
|
||||
// Adjust because we use i !== stop in the for loop
|
||||
stop += diff;
|
||||
// Adjust because we use i !== end in the for loop
|
||||
end += diff;
|
||||
|
||||
for (var i = start; i !== stop; i += diff)
|
||||
var texture = this.textureManager.get(key);
|
||||
|
||||
if (!texture)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
for (var i = start; i !== end; i += diff)
|
||||
{
|
||||
var frame = prefix + Pad(i, zeroPad, '0', 1) + suffix;
|
||||
|
||||
out.push({ key: key, frame: frame });
|
||||
if (texture.has(frame))
|
||||
{
|
||||
out.push({ key: key, frame: frame });
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
|
|
Loading…
Reference in a new issue