jjcale Posted February 18, 2017 Share Posted February 18, 2017 I have purchased the Phaser Virtual Joystick plug-in. It works nicely. In my create function, I have set 50% transparency for DPAD and ButtonA: this.stick = this.pad.addDPad(0, 0, 200, 'dpad'); this.stick.scale = 0.5; this.stick.alpha = 0.5; this.stick.alignBottomLeft(0); this.buttonA = this.pad.addButton(445, 380, 'dpad', 'button1-up', 'button1-down'); this.buttonA.scale = 0.75; this.buttonA.alpha = 0.5; this.buttonA.onDown.add(this.pressButtonA, this); It works well, only that after the game restarts both DPAD and ButtonA are no longer transparent. game.state.start('main'); Any idea? Am I missing something? Thank you! JJ Link to comment Share on other sites More sharing options...
jjcale Posted February 19, 2017 Author Share Posted February 19, 2017 It seems that when the game restarts, the "old" DPAD and ButtonA remain on the screen and thus the new DPAD and ButtonA objects are placed on top, thus 50% + 50% transparency = 100% visibility. Do I need to kill these two objects before restart? Maybe I don't fully understand what happens when game.state.start('main'); is invoked. Puzzled. I am new to Phaser and still learning... JJ Link to comment Share on other sites More sharing options...
Arcanorum Posted February 19, 2017 Share Posted February 19, 2017 I ran into this issue too. What I realised was going on is that the virtual joystick/button sprites are added to the stage, so that it appears above everything else, but as a result it is not removed when the state is changed, or restarted. You need to use this.stick.destroy(); this.buttonA.destroy(); when leaving the state to remove it properly. jjcale 1 Link to comment Share on other sites More sharing options...
jjcale Posted February 19, 2017 Author Share Posted February 19, 2017 Yes. I just figured it out by trial and error: killPlayer: function () { this.stick.destroy (); this.buttonA.destroy (); game.state.start('main'); }, But I don't know what 'stage's is for. Link to comment Share on other sites More sharing options...
jjcale Posted February 21, 2017 Author Share Posted February 21, 2017 Studied the State Manager in more detail, this is cleaner: shutdown: function () { this.stick.destroy (); this.buttonA.destroy (); }, The shutdown method is invoked last before changing/resetting a state. You want to call it as a destructor method for all Stage components. And keep the rest of your code untouched: killPlayer: function () { game.state.start('main'); }, Link to comment Share on other sites More sharing options...
Recommended Posts