Jump to content

Get the animation instance from AnimationManager


Recommended Posts

With this code:


         tempBrick.animations.add('idle', ['brick_' + bID + '_1.png'], 10, false, false);         tempBrick.animations.add('brick_die', [                    'brick_' + bID + '_1.png',                    'brick_' + bID + '_2.png',                    'brick_' + bID + '_3.png',                    'brick_' + bID + '_4.png'                ], 10, false, false);         tempBrick.animations.add('brick_popin', [                    'brick_' + bID + '_4.png',                    'brick_' + bID + '_3.png',                    'brick_' + bID + '_2.png',                    'brick_' + bID + '_1.png'                ], 10, false, false);

And then later I want to play and add custom callback when animation is played:


I saw that there is: onComplete() and also a onAnimationComplete event but for that I need the animation instance...


So what i thought is to get the instance from the sprite.animations ... something like sprite.animations.get("brick_die");

But the animationMnager doesn't have such a thing... there is a 


* @property {object} _anims - An internal object that stores all of the Animation instances.
* @private
this._anims = {};
But I don't think it's supposed to be used...
Also I could make a instance once I'm adding them to the sprite.animation like:
var IdleBrickAnimation = tempBrick.animations.add('idle', ['brick_' + bID + '_1.png'], 10, false, false);
and then:
But since I do it in the different places and methods I expected that there is a way to get a animation by name and then play it and add a callback specifically for this play.




Link to comment
Share on other sites

Hmm nope there isn't a command to bring back a list of animations that have been created (or a single one). However the onAnimationComplete event files from the Sprite, not the Animation itself, so the same event will fire regardless of which animation triggered it (the animation instance is the 2nd parameter sent to the callback).


Equally there's nothing stopping you add the callback directly after playing an animation.

Link to comment
Share on other sites

Hmm here what I made...


        //_brick.animations.play("brick_die", 10, false, true);  //kill the sprite on animation end
        _brick.animations.play("brick_die", 10);  //just play
        _brick.events.onAnimationComplete.add(doSomething, this);
    function doSomething (sprite) {
        //check which animation was finished
        console.log("Animation " + sprite.animations.currentAnim.name + " ended!");
        //sprite.destroy();  //not working
        sprite.kill(); //working



I'll definitely send you some code for the examples about animation finish callbacks and sprite events since there is such a section in the examples


I'm marking the topic as solved cause it's solved but generally there is still a discussion cause you didn't say what do you think of adding such a feature




and/or a custom callback passed as argument to play();  ;)

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...