Flixel Forums

development => help => Topic started by: Dids on Tue, May 3, 2011

Title: Flixel 2.50 & Pausing
Post by: Dids on Tue, May 3, 2011
So, what happened to pausing with the new Flixel release? :-)

Looking to either customize the pause screen or disable it altogether, but there aren't any posts about pausing in 2.50, so I'm a bit lost here.
Title: Re: Flixel 2.50 & Pausing
Post by: photonstorm on Tue, May 3, 2011
Pretty sure Adam took it all out. Build your own pause-screen now, hook it to your own key, set the FlxG paused state yourself. Shame because I used to really like this feature :)
Title: Re: Flixel 2.50 & Pausing
Post by: Dids on Tue, May 3, 2011
Figures, as settings FlxG.paused to true had no effect. Oh well, no biggie!
Just have to remove the out of focus code, but found that already.

PS. A bit off topic, but I absolutely love Quartet. :-)
Title: Re: Flixel 2.50 & Pausing
Post by: photonstorm on Tue, May 3, 2011
Thanks :)
Title: Re: Flixel 2.50 & Pausing
Post by: Adam Atomic on Tue, May 3, 2011
yea pausing is up to you now - the trick with pausing is that unless you are doing a very very specific pause behavior, like you just want a custom "lost focus" screen, anything i built in as automatic behavior is going to be too limited.  If music automatically stops, what about games that want music to keep going?  what if you want to pause but to pull up an inventory screen instead?

my best recommendation is to make your own pause screen by extending flxgroup to make the kind of pause screen that YOU want to use in most of your projects.  then you can just include it or copy-paste it in, and have behavior that you have a lot of control over
Title: Re: Flixel 2.50 & Pausing
Post by: photonstorm on Tue, May 3, 2011
I think the advantage of the old one was that it stopped processing all the calls to update that may have been littered around your classes.

As it stands now all of those calls will still fire, even if your custom pause screen is displayed. Which means all custom class updates now need to be "pause aware", which is a bit of a pain in the arse imhho :)
Title: Re: Flixel 2.50 & Pausing
Post by: alvarocavalcanti on Sat, Aug 6, 2011
Something weird is going on here.

I have a FlxButton that pauses my game:

Code: [Select]
private function OnClickPause():void
{
FlxG.paused = true;
trace("OnClickPause!");
}

And my PlayState.as update function goes like this:

Code: [Select]
override public function update():void
{
if (!FlxG.paused) {
checkMouseInteraction();

checkForTractorBeamCollision();

collisionDetection();

checkForAbduction();

super.update();
}
}

When I click the pause button, the OnClickPause function is called. Ok. BUT, when I click anywhere on the screen, it is called AGAIN. WTF?

I wonder if that's a result of the super.update() call being under that conditional, which somehow keeps the button as the click listener. I tried moving the call outside the conditional, but then my sprites would start falling without colliding...
Title: Re: Flixel 2.50 & Pausing
Post by: alvarocavalcanti on Sat, Aug 6, 2011
As usual, the solution came to me after posting my question. :P

I assumed the super.update() call had to be made, for the button would react as expected. So I had my pause function upgraded:

Code: [Select]
private function OnClickPause():void
{
trace("OnClickPause!");

FlxG.paused = !FlxG.paused;

layerGameObjects.active = !FlxG.paused;

if (FlxG.paused) {
btnPause.loadGraphic(IMG_BTN_PAUSE_RESUME);
} else {
btnPause.loadGraphic(IMG_BTN_PAUSE_NORMAL);
}
}

Then, my update function ended up like this:

Code: [Select]
override public function update():void
{
if (!FlxG.paused) {
checkMouseInteraction();
checkForTractorBeamCollision();
checkForAbduction();
collisionDetection();
}

super.update();
}

A little more work required, but all is fine now. :)
Title: Re: Flixel 2.50 & Pausing
Post by: Mad on Sun, Aug 7, 2011
I think I have a rather elegant solution for pausing. I only have to have code in the state, not in every class.

'pause' is the pause menu FlxGroup.

Code: [Select]
if (!FlxG.paused) {
super.update();
} else {
pause.update();
}

if (FlxG.keys.justPressed("ESCAPE") || FlxG.keys.justPressed("P")) {
if(!FlxG.paused){
FlxG.paused = true;
pause.revive();
} else {
FlxG.paused = false;
pause.alive = false;
pause.exists = false;
}
}

This way the state will stop calling update on all objects added to it, except the pause menu. Super easy to copy and paste over to any state as well!
Title: Re: Flixel 2.50 & Pausing
Post by: photonstorm on Sun, Aug 7, 2011
Nice - you may want to post this to the wiki!
Title: Re: Flixel 2.50 & Pausing
Post by: alvarocavalcanti on Sun, Aug 7, 2011
Elegant for sure! Thanks! I used this approach and the button event bug does not show up. I guess the problem was that I wasn't calling any update at all. :)
Title: Re: Flixel 2.50 & Pausing
Post by: alvarocavalcanti on Thu, Aug 11, 2011
Just a tip for any newcomer. Don't forget to "unpause" (FlxG.paused = false) the game, preferably on the destroy() method. That will asure things behave properly.

I found this out after my buttons (FlxButtonPlus) on the level selection screen stopped working when I switched states via the pause menu.

:)
Title: Re: Flixel 2.50 & Pausing
Post by: test84 on Thu, Apr 5, 2012
I think I have a rather elegant solution for pausing. I only have to have code in the state, not in every class.

'pause' is the pause menu FlxGroup.

Code: [Select]
if (!FlxG.paused) {
super.update();
} else {
pause.update();
}

if (FlxG.keys.justPressed("ESCAPE") || FlxG.keys.justPressed("P")) {
if(!FlxG.paused){
FlxG.paused = true;
pause.revive();
} else {
FlxG.paused = false;
pause.alive = false;
pause.exists = false;
}
}

This way the state will stop calling update on all objects added to it, except the pause menu. Super easy to copy and paste over to any state as well!

Nice.

Correct me if I'm wrong but to get it work I had to make the group's alive and exists to false. Is it necessary or did I miss anything?

Because if I "add" it to the state, it will get drawn always and if not, it will not ever, so I "add" it and then set it's alive and exists to false, right? I'm skeptic to my method because no one said anything about it here.
Title: Re: Flixel 2.50 & Pausing
Post by: Jeff on Wed, May 9, 2012
I think I have a rather elegant solution for pausing. I only have to have code in the state, not in every class.

'pause' is the pause menu FlxGroup.

Code: [Select]
if (!FlxG.paused) {
super.update();
} else {
pause.update();
}

if (FlxG.keys.justPressed("ESCAPE") || FlxG.keys.justPressed("P")) {
if(!FlxG.paused){
FlxG.paused = true;
pause.revive();
} else {
FlxG.paused = false;
pause.alive = false;
pause.exists = false;
}
}

This way the state will stop calling update on all objects added to it, except the pause menu. Super easy to copy and paste over to any state as well!

This is about exactly what I wrote for pausing as well. The only difference is that when pausing I'm calling:

Code: [Select]
add(infoScreen = new InfoScreen(1));and when unpausing, I'm calling:
Code: [Select]
infoScreen.killScreen();
For a while, it seemed like the whole thing was working properly, but as I was testing around with the game more, I noticed that after I've visited the pauseScreen once, trying to change states will cause a crash. I pinpointed the problem into the camera that's showing the screen, and it seems to be a problem with calling destroy() on the camera. Here's the line of code (in killScreen() function) that causes the problem:

Code: [Select]
FlxG.removeCamera(infoCam, false);
If I have it like this, I can pause and unpause the game just fine. The problem is that once I try to switchState after pausing and unpausing, I get:
Quote
[Fault] exception, information=ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
And if I put the remove to also destroy the camera like this:
Code: [Select]
FlxG.removeCamera(infoCam, true);unpausing immediately gives:
Quote
exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.

Well, in fact I've already found a way to make this work, namely by just setting the camera invisible instead of removing it. So in that sense I don't currently have a problem, but I'd still like to understand why I'm not allowed to remove the camera? Or more likely: what am I doing wrong when trying to remove the camera this way? Any ideas?
Title: Re: Flixel 2.50 & Pausing
Post by: xhunterko on Wed, May 9, 2012
Here's how I do dialogue boxes and pauses now:

http://forums.flixel.org/index.php/topic,6303.0.html

Enjoy!