gwalchmei Posted February 4, 2015 Share Posted February 4, 2015 Hello, I want to execute a function at the end of a tweens chain. Here is an example of what I did :var currentTween = null;var prevTween = null;myGroup.forEach(function (obj){ currentTween = game.add.tween(sprite).to({ x: obj.x, y: obj.y }, 100, Phaser.Easing.Linear.None); if(prevTween){ prevTween.chain(currentTween); } else { sprite.movementAnimation = currentTween; } prevTween = currentTween;});/* add here the onComplete callback */sprite.movementAnimation.start();My animation works like a charm. First I tried :sprite.movementAnimation.onComplete.add(myFunction, this);=> myFunction executes at the end of the first tween. Then I tried :sprite.movementAnimation.onChildComplete.add(myFunction, this);=> myFunction is never called but I have no errors. Then I tried :sprite.movementAnimation._lastChild.onComplete.add(myFunction, this);=> I get the error "Uncaught TypeError: Cannot read property 'onComplete' of undefined" (in fact console.log(sprite.movementAnimation._lastChild) returns undefined) Could one of you explain me what I did wrong or show me another way to achieve what I want to do ? Thanks. Link to comment Share on other sites More sharing options...
charlie_says Posted February 6, 2015 Share Posted February 6, 2015 ok, I've done this, and think you're pretty close this:sprite.movementAnimation._lastChild.onComplete.add(myFunction, this);should besprite.movementAnimation._lastChild.onComplete.add(this.myFunction, this); Link to comment Share on other sites More sharing options...
gwalchmei Posted February 9, 2015 Author Share Posted February 9, 2015 The _lastChild property is undefined (and I can't find it on the API (http://docs.phaser.io/Phaser.Tween.html ) Link to comment Share on other sites More sharing options...
mwatt Posted February 9, 2015 Share Posted February 9, 2015 I also like to see _lastChild fixed (and documented) or some similar alternative. I needed to do this in the game I am developing but had to opt out of a particular enhancement, at least for now. Link to comment Share on other sites More sharing options...
Recommended Posts