123shansun Posted August 10, 2014 Share Posted August 10, 2014 Hi,There are five states in my demo game. when the game is in play state---> if the game is paused ---> if menu is clicked ---> then go to menu state (but game freezes here ) --->else --->destroy menu image and unpause the game.(this part works perfectly ) I have attched a sample file.It is based on phaser examples --> misc --> pause menu Thank you!! sample.txt Link to comment Share on other sites More sharing options...
eguneys Posted August 10, 2014 Share Posted August 10, 2014 can you ever go to Menu state, for example from the preloader state. If yes, post your Menu state code here. you don't need to attach files, just paste it here. Link to comment Share on other sites More sharing options...
DELETE THIS ACC PLS Posted August 10, 2014 Share Posted August 10, 2014 I think it freezes because you paused the game. There's no listeners for the menu item.Try to put this code in your create function:// Identify your menu sprite here (this line)menu.inputEnabled = true;menu.events.onInputUp.add(function () { game.state.start('Menu');});Not so sure it'll work but if it doesn't it must be something similar. When your game is paused your if statements doesn't run. Link to comment Share on other sites More sharing options...
123shansun Posted August 11, 2014 Author Share Posted August 11, 2014 Thanks for the reply Guys!! can you ever go to Menu state, for example from the preloader state. If yes, post your Menu state code here. you don't need to attach files, just paste it here. This is the code for going from preload to menuGame.Load.prototype = { preload: function() {............ }, create: function() { game.state.start('Menu'); // this is used to go from preload to menu }};------------------------And this is the code in menu state for going to play state update: function() { if (this.cursor.up.isDown) this.game.state.start('Play'); }-----------------------I think it freezes because you paused the game. There's no listeners for the menu item.Try to put this code in your create function:// Identify your menu sprite here (this line)menu.inputEnabled = true;menu.events.onInputUp.add(function () { game.state.start('Menu');});Not so sure it'll work but if it doesn't it must be something similar. When your game is paused your if statements doesn't run.This is the code in play state game.input.onDown.add(unpause, self); //method that handles the pause menu function unpause(event) { // Only act if paused if (game.paused) { // Calculate the corners of the menu var x1 = w / 2 - 270 / 2, x2 = w / 2 + 270 / 2, y1 = h / 2 - 180 / 2, y2 = h / 2 + 180 / 2; // Check if the click was inside the menuif (event.x > x1 && event.x < x2 && event.y > y1 && event.y < y2) {//if menu area is clicked go to main menumenu.events.onInputUp.add(function () {game.state.start('Menu');//this is the only part that doesn't work and I don't know what I'm doing wrong}); } else {menu.destroy();game.paused = false; } }--------------------------Thanks for the help guys ! Link to comment Share on other sites More sharing options...
DELETE THIS ACC PLS Posted August 11, 2014 Share Posted August 11, 2014 I think for what you're doing you should consider pausing the game in another way. Since a lot of things won't work if game.paused === true.You can check this Handy tutorial by Loopeex You can see how he pauses the game without game.paused === true. In his way things will run normally and nothing will stop since game won't freeze. I don't think this function would work if game is paused. Try the tutorial better. (In the Phaser example there wasn't such a line. Since it's hard to do it.)menu.events.onInputUp.add(function () {game.state.start('Menu');}); Link to comment Share on other sites More sharing options...
123shansun Posted August 11, 2014 Author Share Posted August 11, 2014 I think for what you're doing you should consider pausing the game in another way. Since a lot of things won't work if game.paused === true.You can check this Handy tutorial by Loopeex You can see how he pauses the game without game.paused === true. In his way things will run normally and nothing will stop since game won't freeze. I don't think this function would work if game is paused. Try the tutorial better. (In the Phaser example there wasn't such a line. Since it's hard to do it.)menu.events.onInputUp.add(function () {game.state.start('Menu');}); Thanks Hady Hayman !! DELETE THIS ACC PLS 1 Link to comment Share on other sites More sharing options...
Recommended Posts