Jump to content

onComplete function of chained tweens triggers after the first tween is completed


valueerror
 Share

Recommended Posts

Try naming your tweens and attaching handlers to the desired tween.

 

Here is some super psuedocode

 

var up      = tween

var down = tween

 

down.onComplete.add(function () {})

 

up.chain(down).start()

 

There is an example of doing exactly this here in a little quick multiplayer game prototype I was developing in ES6 a few months ago:

 

https://github.com/stevekane/lttp/blob/master/public/entities/Player.js

 

lines 37 - 60

 

Hope this helps.

 

Steve

Link to comment
Share on other sites

well.. this works ! it starts the onComplete function i want at the end of the second tween..    but...    there's always a but..   the function is triggered twice..  once for every tween in the row...  this _lastChild method solved the problem with the tween starting after the first part of the tween .. but this seems to be another problem... :(

Link to comment
Share on other sites

ok... because adding onComplete on chained tweens sucks ;-)   (it either adds the function to the first tween in the chain instead of the last and/or adds it to both or something else i don't understand

i used the second approach  steve kane proposed..

 

this works like charm and is actually a very beautiful solution for my case.. 

 

so this is the code that works :

    var ascent = game.add.tween(body.sprite.scale).to({x:max,y:max}, upTime, Phaser.Easing.Sinusoidal.Out)    var descent = game.add.tween(body.sprite.scale).to({x:originalScale,y:originalScale}, downTime, Phaser.Easing.Sinusoidal.In)    descent.onComplete.add(function(){     checkHitLandig(body);  });    ascent.chain(descent).start();

thx again..

 

do you think this is a bug?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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