Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

[Solved] Virtual Joystick's transparency after game.state.start()


jjcale
 Share

Recommended Posts

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

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

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.

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...