Sign in to follow this  

Buttons set to fixedToCamera disappears after game reset.

Recommended Posts

Exactly as it says on the tin.

The buttons in question are on-screen buttons, for mobile devices. Here's my code them.

this.touchBtnUp =, - 300, 'ctrlBtn_up', this.touchUpCallback, this, 'btn_up.png');
this.touchBtnDown =, - 150, 'ctrlBtn_down', this.touchDownCallback, this, 'btn_down.png');
this.touchBtnLeft =, - 150, 'ctrlBtn_left', this.touchLeftCallback, this, 'btn_left.png');
this.touchBtnRight =, - 150, 'ctrlBtn_right', this.touchRightCallback, this, 'btn_right.png');

this.touchBtnUp.fixedToCamera = true;
this.touchBtnDown.fixedToCamera = true;
this.touchBtnLeft.fixedToCamera = true;
this.touchBtnRight.fixedToCamera = true;

Nothing out of place, except for one thing: 'ctrlBtn_up' doesn't exist as a spritesheet. Since this is a temporary code, I've used temporary assets, which are not in a spritesheet, but individually created. I'm not sure if that has an effect on anything.

Now, come game over, I show a game over layer (if the player wins) or immediately reset the game (if the player loses). Here's my code for those:

  this.gameOverLayer = new GameOverLayer(;
  this.gameOverLayer.fixedToCamera = true;

  console.log("Restart Level");
  this.bIsGameOver = true;
  var slideOut = Phaser.Plugin.StateTransition.Out.ScaleUp;
  slideOut.duration = 1000;

  var slideIn = Phaser.Plugin.StateTransition.In.SlideBottom;
  slideIn.duration = 1000;'gameplay' , slideOut );

endGame() {
  //Finished Level
  console.log("Finished Level");

And the game over layer has a button that essentially does the same thing as the restartGame function.

However, whether the game is over or restarts, the buttons go missing on the next play through (reloading the browser makes them show up again).

I've tried resetting the x and y, but to no avail.

About the only thing that works is to disable the fixedToCamera but that would mean the buttons getting left behind when the player moves.

Anything else I can try?

Share this post

Link to post
Share on other sites

it sounded like you've messed up the scoping rules of JavaScript (since I don't see the whole code that would be the best assumption) untill you mentioned that disabling "fixedToCamera" fixes the issue. I'm at a loss now.

Share this post

Link to post
Share on other sites

I don't know if I'm reading it right, but if the buttons are in the first scene, they'll get removed when you switch to a second scene. That's normal.

Also try it without the plugin (as in don't load the plugin at all).

Share this post

Link to post
Share on other sites

Fixed it. The problem is with this code:

this.touchBtnUp =, - 300, 'ctrlBtn_up', this.touchUpCallback, this, 'btn_up.png');

For some reason, on game restart, the changes. So it's less a case of it disappearing than it is getting set up in the wrong place.

For now, I just hard-coded in my usual height, until I figure out why that changes.

Share this post

Link to post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.