zack_falcon Posted May 18, 2018 Share Posted May 18, 2018 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 = this.game.add.button(160, this.game.world.height - 300, 'ctrlBtn_up', this.touchUpCallback, this, 'btn_up.png'); this.touchBtnDown = this.game.add.button(160, this.game.world.height - 150, 'ctrlBtn_down', this.touchDownCallback, this, 'btn_down.png'); this.touchBtnLeft = this.game.add.button(20, this.game.world.height - 150, 'ctrlBtn_left', this.touchLeftCallback, this, 'btn_left.png'); this.touchBtnRight = this.game.add.button(300, this.game.world.height - 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: create() { this.gameOverLayer = new GameOverLayer(this.game); this.gameOverLayer.fixedToCamera = true; } restartGame() { 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; this.game.state.start('gameplay' , slideOut ); } endGame() { //Finished Level console.log("Finished Level"); this.gameOverLayer.showGameOver(0); } 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? Link to comment Share on other sites More sharing options...
Mickety Posted May 18, 2018 Share Posted May 18, 2018 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. Link to comment Share on other sites More sharing options...
samme Posted May 19, 2018 Share Posted May 19, 2018 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). Link to comment Share on other sites More sharing options...
zack_falcon Posted May 21, 2018 Author Share Posted May 21, 2018 Fixed it. The problem is with this code: this.touchBtnUp = this.game.add.button(160, this.game.world.height - 300, 'ctrlBtn_up', this.touchUpCallback, this, 'btn_up.png'); For some reason, on game restart, the game.world.height 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. Link to comment Share on other sites More sharing options...
samme Posted May 21, 2018 Share Posted May 21, 2018 You may want game.world.bounds.height. Link to comment Share on other sites More sharing options...
Recommended Posts