mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
create
no longer throws a warning, returns existing animation. Also added exists
method.
This commit is contained in:
parent
1a407bc4f5
commit
20ea562d23
1 changed files with 41 additions and 10 deletions
|
@ -154,32 +154,63 @@ var AnimationManager = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if the given key is already in use within the Animation Manager or not.
|
||||
*
|
||||
* Animations are global. Keys created in one scene can be used from any other Scene in your game. They are not Scene specific.
|
||||
*
|
||||
* @method Phaser.Animations.AnimationManager#exists
|
||||
* @since 3.16.0
|
||||
*
|
||||
* @param {string} key - The key of the Animation to check.
|
||||
*
|
||||
* @return {boolean} `true` if the Animation already exists in the Animation Manager, or `false` if the key is available.
|
||||
*/
|
||||
exists: function (key)
|
||||
{
|
||||
return this.anims.has(key);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Animation and adds it to the Animation Manager.
|
||||
*
|
||||
* Animations are global. Once created, you can use them in any Scene in your game. They are not Scene specific.
|
||||
*
|
||||
* If an invalid key is given this method will return `false`.
|
||||
*
|
||||
* If you pass the key of an animation that already exists in the Animation Manager, that animation will be returned.
|
||||
*
|
||||
* A brand new animation is only created if the key is valid and not already in use.
|
||||
*
|
||||
* If you wish to re-use an existing key, call `AnimationManager.remove` first, then this method.
|
||||
*
|
||||
* @method Phaser.Animations.AnimationManager#create
|
||||
* @fires AddAnimationEvent
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {AnimationConfig} config - The configuration settings for the Animation.
|
||||
*
|
||||
* @return {Phaser.Animations.Animation} The Animation that was created.
|
||||
* @return {(Phaser.Animations.Animation|false)} The Animation that was created, or `false` is the key is already in use.
|
||||
*/
|
||||
create: function (config)
|
||||
{
|
||||
var key = config.key;
|
||||
|
||||
if (!key || this.anims.has(key))
|
||||
{
|
||||
console.warn('Invalid Animation Key, or Key already in use: ' + key);
|
||||
return;
|
||||
}
|
||||
var anim = false;
|
||||
|
||||
var anim = new Animation(this, key, config);
|
||||
if (key)
|
||||
{
|
||||
anim = this.get(key);
|
||||
|
||||
if (!anim)
|
||||
{
|
||||
anim = new Animation(this, key, config);
|
||||
|
||||
this.anims.set(key, anim);
|
||||
|
||||
this.emit('add', key, anim);
|
||||
}
|
||||
}
|
||||
|
||||
return anim;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue