SPARKY892 Posted April 1, 2015 Share Posted April 1, 2015 Hi I am currently working on a game using phaser but having problems where I want to display a button that you click once to start charging a power bar and then click again to set the power but once you do this the button should hide until the item being launched comes to rest for you to then repeat the process as needed. I have tried using button.visible = false, but nothing appears to change and outputting the value to the console shows it is false. Thanks in advance for any help Link to comment Share on other sites More sharing options...
rich Posted April 1, 2015 Share Posted April 1, 2015 visible is the right property to use. You'll need to share some code / url for anyone to help further really. Link to comment Share on other sites More sharing options...
SPARKY892 Posted April 1, 2015 Author Share Posted April 1, 2015 The button is created here: SwingB = this.game.add.button(1400, 830, "SwingButton", this.Swing, this, 0, 0, 0, 0); The property is changed here: Swing: function() { if (Started == true){ //this.game.camera.follow(Ball, Phaser.Camera.FOLLOW_TOPDOWN); var VelocityX = (Power * Math.cos((Arrow.angle -90) * Radian) * 10); var VelocityY = (Power * Math.sin((Arrow.angle -90) * Radian) * 10); Ball.body.velocity.x += VelocityX; Ball.body.velocity.y += VelocityY; Started = false; this.PowerF.visible = false; this.PowerB.visible = false; this.SwingB.visible = false; } if (Started == false) { this.PowerB = this.game.add.sprite(1400, 830, "PowerBar"); this.PowerF = this.game.add.sprite(1649, 1080, "PowerFill"); this.PowerF.anchor.setTo(0.5, 1); this.PowerB.fixedToCamera = true; this.PowerF.fixedToCamera = true; this.PowerF.rotation = 181 * Radian; Power = 0; Started = true; } Block.body.onBeginContact.add(this.StartEmitter, this); }, PowerF and PowerB both disappear fine though they are sprites if that makes a difference. Link to comment Share on other sites More sharing options...
rich Posted April 1, 2015 Share Posted April 1, 2015 A Button is just a sprite too, so I don't think it's that. You should use a strict equality check for booleans: if (Started === true) and === false, otherwise I believe the issue is elsewhere - perhaps Swing is being called multiple times (log it out and see), once hiding it and once showing it. Perhaps the button visibility is being reset somewhere else. Maybe the button you're seeing on-screen isn't the button you thought was hidden at all (i.e. it spawned a new one in its place). There are all kinds of things it could be I'm afraid. Link to comment Share on other sites More sharing options...
Recommended Posts