[SOLVED] Javascript: waiting for animation to finish

Game development with Board Game Arena Studio
Post Reply
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

[SOLVED] Javascript: waiting for animation to finish

Post by apollo1001 »

Hi,

I've chained some animations together and am wondering how I can get the normal javascript code to wait for their completion before continuing. At the moment the calls after 'play()' are firing whilst the animation is in progress.

I'm clearly missing something simple, so any advice appreciated!

Adam

Code: Select all

var combined_anim = dojo.fx.chain(potion_ready_anims);
dojo.connect(combined_anim, 'onEnd', function(node) { 
    // Ideally need to have this onEnd method trigger the final few methods 
    dojo.destroy('potion_' + potion_id); });
combined_anim.play();

// These need to run after the animation has completed or somehow be inserted into the chain at the correct point
this.updateDispenser(tube1, tube2, tube3, tube4, tube5);  
this.cupboards[player_id].addToStockWithId(potion_type, potion_id, 'potion_' + potion_id);
Last edited by apollo1001 on 15 April 2020, 09:06, edited 1 time in total.
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: Javascript: waiting for animation to finish

Post by DrKarotte »

The disc animation chain in the Reversi tutorial has the onEnd function as part of the chain, perhaps this makes a difference? I am not an expert on this, quite the opposite.
User avatar
Tanguy_D
Posts: 4
Joined: 09 May 2017, 09:14

Re: Javascript: waiting for animation to finish

Post by Tanguy_D »

I had an issue like you, and solved my problem like this :

Code: Select all

combined_anim.onEnd = function() {
// Your code
};
We should add 'onEnd' on each animation object on a combined / chain, but dojo does not handle it very well.
User avatar
apollo1001
Posts: 191
Joined: 21 July 2015, 10:41

Re: Javascript: waiting for animation to finish

Post by apollo1001 »

Thank you for the replies. I have now found the solution:

Code: Select all

dojo.connect(animation_id, 'onEnd', dojo.hitch(this, 'callback_function', parameters));
Post Reply

Return to “Developers”