uyerdna Posted February 7, 2015 Share Posted February 7, 2015 Hi guys I'm still really new in this whole JS thing so I get easily confused while writing down my ideas. Currently I'm stuck with writing tween correctly. Would be great if someone can see my code and tell me what's wrong this.readyText = new Phaser.BitmapText(this.game, this.game.width/2 - 100, 500, 'littera', 'R E A D Y', 42);this.readyTween = this.game.add.tween(this.readyText).to( { y: this.game.height/2 }, 500, Phaser.Easing.Linear.None, true);this.readyTween.onComplete.addOnce(function(){ this.readyText.text = 'SET'; // want to change the text, but it won't work this.readyTween.to( { y: 600 }, 500, Phaser.Easing.Linear.None, true); // try to tween it but won't work either });Seems like I'm lost in this whole 'this' scope thingy in JS. I'd really grateful if someone could point me to the right direction. I'm using Phaser 2.2.2. Thanks in advance! Link to comment Share on other sites More sharing options...
Tom Atom Posted February 7, 2015 Share Posted February 7, 2015 Just try this note("this" word added as last parameter in the very end of your code): this.readyText = new Phaser.BitmapText(this.game, this.game.width / 2 - 100, 500, 'littera', 'R E A D Y', 42); this.readyTween = this.game.add.tween(this.readyText).to({ y: this.game.height / 2 }, 500, Phaser.Easing.Linear.None, true); this.readyTween.onComplete.addOnce(function () { this.readyText.text = 'SET'; // want to change the text, but it won't work this.readyTween.to({ y: 600 }, 500, Phaser.Easing.Linear.None, true); // try to tween it but won't work either }, this); Link to comment Share on other sites More sharing options...
uyerdna Posted February 7, 2015 Author Share Posted February 7, 2015 Ah, that works perfectly! I can't believe I spent a few hours just because I didn't add 'this' to addOnce Thank you very much, Tom! You're a life saver! Link to comment Share on other sites More sharing options...
Recommended Posts