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

Sprite won't appear 1st time game is paused


BadBearGames
 Share

Recommended Posts

Hey guys, first time posting here. I have a black background sprite that appears when my game is paused to fade out the screen. In the create function I create it, set its alpha to 0.5, and set its visible value to false (I also put the body to null if that makes a difference). When the paused button is pressed, I set its visible property to true and pause the game. In my update function I set its visible to false, so that when the game isn't paused, the background is hidden. For some reason this doesn't work the first time I pause the game, but it works every time after that. It just really bothers me. Is there something I'm missing? Thank you.

Link to comment
Share on other sites

//I have a lot of code, so I just put in the lines related to the problem//I'm using the full screen mobile templatecreate: function() {pausedFade_mc = this.add.sprite(0, 0, 'background1');pausedFade_mc.anchor.setTo(0.5, 0.5);pausedFade_mc.scale.setTo(4, 4);pausedFade_mc.alpha = 0.5;pausedFade_mc.visible = false;pausedFade_mc.body = null;}'update: function() {if (pausedFade_mc){    paused_txt.visible = false;    pausedFade_mc.visible = false;}},function pauseGame() { //Pauses the game when called    paused_txt.visible = true;    paused_txt.x = playerBody_mc.x;    paused_txt.y = playerBody_mc.y + 200;    pausedFade_mc.visible = true;    pausedFade_mc.alpha = 0.5;    pausedFade_mc.x = playerBody_mc.x;    pausedFade_mc.y = playerBody_mc.y;    thisGame.paused = true;}

@Kobaltic There you go :)

Link to comment
Share on other sites

  • 1 month later...

Maybe pauseGame is being called before update? Setting it to visible, then instantly back to invisible?

 

Something may be tripping up the code the first time it happens. Something might not be loaded in properly until the first time...

 

This is all speculation really. Maybe set up some console.log flags to keep track of when exactly the visible property is changed.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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