Earest Posted January 22, 2015 Share Posted January 22, 2015 Hi, i tried to make a game with a pause menu but, i only success to supress resume button (not the restart or the menu button) when i click on it. I've tried with remove child and remove but it's don't work. RestartButton =game.Class.extend({ init:function(){ this.sprite = new game.Sprite('run'); this.sprite.interactive = true; this.sprite.mousedown= this.sprite.tap = function() { game.scene.stage.pausedGame=false; this.remove(); //Need Help here }; this.restartChoice = new game.Text("Restart", {font: '40px wallfont',fill: "#ffffff",align: "center"}); this.restartChoice.position = {x: 30, y:120}; this.restartChoice.interactive = true; this.restartChoice.click = this.restartChoice.tap = function () { game.system.setScene(TestGame, true); }; this.menu = new game.Text("Menu", {font: '40px wallfont', fill: "#ffffff", align: "center"}); this.menu.position = {x: 30, y: 160}; this.menu.interactive = true; this.menu.click = this.menu.tap = function () { game.system.setScene(MenuGame, true); }; }, displayButton:function() { this.sprite.position.x=5; this.sprite.position.y=50; game.scene.stage.addChild(this.sprite); game.scene.addObject(this.sprite); game.scene.stage.addChild(this.restartChoice); game.scene.addObject(this.sprite); game.scene.stage.addChild(this.menu); game.scene.addObject(this.sprite); }}); Quote Link to comment Share on other sites More sharing options...
enpu Posted January 22, 2015 Share Posted January 22, 2015 Try to bind your mousedown function:game.createClass('RestartButton', { init: function() { this.sprite = new game.Sprite('run'); this.sprite.mousedown = this.sprite.tap = this.mousedown.bind(this); }, mousedown: function() { this.sprite.remove(); }}); Earest 1 Quote Link to comment Share on other sites More sharing options...
Earest Posted January 22, 2015 Author Share Posted January 22, 2015 It only work for the sprite, if i try to remove restartChoice and menu with the same way mousedown:function() { this.sprite.remove(); this.restartChoice.remove(); this.menu.remove(); }i get this error"this.restartChoice.remove is not a function" Quote Link to comment Share on other sites More sharing options...
enpu Posted January 22, 2015 Share Posted January 22, 2015 Ah sorry game.Text does not have remove function, instead use:game.scene.stage.removeChild(this.restartChoice);Note that Text is pretty slow on performance, so i would suggest to use BitmapText instead. Earest 1 Quote Link to comment Share on other sites More sharing options...
Earest Posted January 22, 2015 Author Share Posted January 22, 2015 Work perfectely Thanks Enpu (Have to put a solve tag on the title or something like that?) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.