Mike018 Posted July 13, 2016 Share Posted July 13, 2016 GSAP works great with Phaser, but I haven't figured out how to use Phaser specific things in a GSAP onComplete function. Here's an example. I can't create a sprite via an onComplete function because it uses something specific to Phaser. At least I think that's the problem, but I can tween something using this.game.world.centerX and other Phaser position parameters. This example gives me this error: Cannot read property 'add' of undefined. Any ideas? TweenMax.to(this.object, 1, {x:"+=20", onComplete: this.testFunction}) testFunction() { this.game.add.sprite( this.game.world.centerX, this.game.world.centerY, 'object5' ); } Link to comment Share on other sites More sharing options...
LTNGames Posted July 13, 2016 Share Posted July 13, 2016 You mean something like this? This is what I use for a few of my windows in my game. var tween; var destination = 400; var duration = 500 tween = this.game.add.tween(this).to( { y: destination }, duration, Phaser.Easing.Linear.None, true); tween.onStart.add(function () { // Add stuff }, this); tween.onComplete.add(function () { // Add stuff }, this); Link to comment Share on other sites More sharing options...
Mike018 Posted July 13, 2016 Author Share Posted July 13, 2016 1 hour ago, LTNGames said: You mean something like this? This is what I use for a few of my windows in my game. var tween; var destination = 400; var duration = 500 tween = this.game.add.tween(this).to( { y: destination }, duration, Phaser.Easing.Linear.None, true); tween.onStart.add(function () { // Add stuff }, this); tween.onComplete.add(function () { // Add stuff }, this); That's using the Phaser tween engine. My question is regarding the GSAP animation library. Link to comment Share on other sites More sharing options...
mcolman Posted July 14, 2016 Share Posted July 14, 2016 This is a scope issue. The value of 'this' is not what you expected. Supply 'onCompleteScope: this' into your GSAP tween drhayes and Mike018 2 Link to comment Share on other sites More sharing options...
Recommended Posts