phaser/src/gameobjects/BuildGameObjectAnimation.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-04-11 02:13:30 +00:00
var GetAdvancedValue = require('../utils/object/GetAdvancedValue');
var BuildGameObjectAnimation = function (sprite, config)
{
var animConfig = GetAdvancedValue(config, 'anims', null);
if (animConfig === null)
{
return sprite;
}
if (typeof animConfig === 'string')
{
// { anims: 'key' }
sprite.anims.play(animConfig);
}
else if (typeof animConfig === 'object')
{
// { anims: {
// key: string
// startFrame: [string|integer]
// delay: [float]
// repeat: [integer]
// repeatDelay: [float]
// yoyo: [boolean]
// play: [boolean]
// delayedPlay: [boolean]
// }
// }
var anims = sprite.anims;
2017-04-11 02:13:30 +00:00
var key = GetAdvancedValue(animConfig, 'key', undefined);
var startFrame = GetAdvancedValue(animConfig, 'startFrame', undefined);
var delay = GetAdvancedValue(animConfig, 'delay', 0);
var repeat = GetAdvancedValue(animConfig, 'repeat', 0);
var repeatDelay = GetAdvancedValue(animConfig, 'repeatDelay', 0);
var yoyo = GetAdvancedValue(animConfig, 'yoyo', false);
2017-09-13 16:10:21 +00:00
var play = GetAdvancedValue(animConfig, 'play', false);
var delayedPlay = GetAdvancedValue(animConfig, 'delayedPlay', 0);
2017-04-11 02:13:30 +00:00
anims.delay(delay);
anims.repeat(repeat);
anims.repeatDelay(repeatDelay);
anims.yoyo(yoyo);
2017-09-13 16:10:21 +00:00
if (play)
2017-04-11 02:13:30 +00:00
{
anims.play(key, startFrame);
}
2017-09-13 16:10:21 +00:00
else if (delayedPlay > 0)
{
anims.delayedPlay(delayedPlay, key, startFrame);
}
2017-04-11 02:13:30 +00:00
else
{
2017-09-13 16:10:21 +00:00
anims.load(key);
2017-04-11 02:13:30 +00:00
}
}
return sprite;
};
module.exports = BuildGameObjectAnimation;