mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Added animation build function.
This commit is contained in:
parent
fcc01d28aa
commit
dabfbc0ae1
1 changed files with 64 additions and 0 deletions
64
v3/src/gameobjects/BuildGameObjectAnimation.js
Normal file
64
v3/src/gameobjects/BuildGameObjectAnimation.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
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 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);
|
||||
|
||||
var anims = sprite.anims;
|
||||
|
||||
anims.delay(delay);
|
||||
anims.repeat(repeat);
|
||||
anims.repeatDelay(repeatDelay);
|
||||
anims.yoyo(yoyo);
|
||||
|
||||
if (GetAdvancedValue(animConfig, 'play', true))
|
||||
{
|
||||
anims.play(key, startFrame);
|
||||
}
|
||||
else
|
||||
{
|
||||
var d = GetAdvancedValue(animConfig, 'delayedPlay', 0);
|
||||
|
||||
if (d > 0)
|
||||
{
|
||||
anims.delayedPlay(d, key, startFrame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sprite;
|
||||
};
|
||||
|
||||
module.exports = BuildGameObjectAnimation;
|
Loading…
Add table
Reference in a new issue