Biggerplay Posted January 30, 2014 Share Posted January 30, 2014 How can I remove a tween/object that is being tweened when it's completed tweening? Link to comment Share on other sites More sharing options...
powerfear Posted January 30, 2014 Share Posted January 30, 2014 The tween should remove itself automatically once completed, if you want to remove the object being tweened use something like an onComplete callback and remove the object from wherever it is. Link to comment Share on other sites More sharing options...
Biggerplay Posted January 30, 2014 Author Share Posted January 30, 2014 How can I use the callback though? I've tried.. bounce.onComplete.add(this.removeTween(scoreText), this);removeTween:function(textToRemove){ textToRemove.destroy(); },and it's giving me an error. Link to comment Share on other sites More sharing options...
programlocura Posted January 30, 2014 Share Posted January 30, 2014 Hi!If "bounce" it's a tween...var bounce = game.add.tween( object ).to().start();For 1.1.3bounce.onCompleteCallback( function() { this.removeTween(scoreText);});For 1.1.4 (Only available on dev branch)bounce.onComplete( function() { this.removeTween(scoreText);});I hope it helps! Link to comment Share on other sites More sharing options...
Biggerplay Posted January 30, 2014 Author Share Posted January 30, 2014 @programlocura I'm using 1.1.3 I tried that but it's giving me the error "Uncaught TypeError: Object #<Object> has no method 'removeTween'" I'm fairly certain there's something wrong in this function as I'm new to JS so here's the complete function.. risingText:function(text, xx, yy) { var scoreText = this.game.add.bitmapText(xx, yy, text, { font: '48px Allgemeine', align: 'left' }); var bounce= this.game.add.tween(scoreText); bounce.to({ x: xx, y: yy-60 }, 1000 + Math.random() * 3000, Phaser.Easing.Linear.In); bounce.start(); bounce.onCompleteCallback( function() { this.game.removeTween(scoreText); }); }, Link to comment Share on other sites More sharing options...
Zeterain Posted January 30, 2014 Share Posted January 30, 2014 You are trying to call the function removeTween on your game object. (line 12) The game object doesn't have such a function, which is why you are getting your error. What you want to do is remove the tween from the game's tween manager. Replace line 12 with: this.game.tweens.remove(bounce); //tweens is a reference to the tween managerThis line works on Phaser 1.1.3 and 1.1.4 miuan and kstamatov85 2 Link to comment Share on other sites More sharing options...
Biggerplay Posted January 30, 2014 Author Share Posted January 30, 2014 You are trying to call the function removeTween on your game object. (line 12) The game object doesn't have such a function, which is why you are getting your error. What you want to do is remove the tween from the game's tween manager. Replace line 12 with: this.game.tweens.remove(bounce); //tweens is a reference to the tween managerThis line works on Phaser 1.1.3 and 1.1.4Does that remove the scoreText when the tween is complete? Link to comment Share on other sites More sharing options...
powerfear Posted January 30, 2014 Share Posted January 30, 2014 If you just want to remove the text do:bounce.onCompleteCallback( function() { this.group.remove(this);});If you want to completely delete the text do:bounce.onCompleteCallback( function() { this.destroy();}); Link to comment Share on other sites More sharing options...
Zeterain Posted January 30, 2014 Share Posted January 30, 2014 Oh, sorry, I misread your post. If you want to remove the text when the tween is complete, I would call the destroy function on the scoreText object. So replace line 12 with: scoreText.destroy();Let me know if that does what you need. Biggerplay 1 Link to comment Share on other sites More sharing options...
Recommended Posts