Author Topic: Flixel 2.50 & Pausing  (Read 8120 times)

Dids

  • Member
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Flixel 2.50 & Pausing
« 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.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Flixel 2.50 & Pausing
« Reply #1 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 :)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Dids

  • Member
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Flixel 2.50 & Pausing
« Reply #2 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. :-)

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Flixel 2.50 & Pausing
« Reply #3 on: Tue, May 3, 2011 »
Thanks :)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Adam Atomic

  • Founder
  • Key Contributor
  • *****
  • Posts: 852
  • Karma: +0/-0
  • new dad
    • View Profile
    • Adam Atomic
Re: Flixel 2.50 & Pausing
« Reply #4 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

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Flixel 2.50 & Pausing
« Reply #5 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 :)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

alvarocavalcanti

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
    • Loodo - A Blog about Games and Game Design
Re: Flixel 2.50 & Pausing
« Reply #6 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...
Alvaro Cavalcanti
Loodo - A blog about Games and Game Design
http://www.loodo.com.br

alvarocavalcanti

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
    • Loodo - A Blog about Games and Game Design
Re: Flixel 2.50 & Pausing
« Reply #7 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. :)
Alvaro Cavalcanti
Loodo - A blog about Games and Game Design
http://www.loodo.com.br

Mad

  • Member
  • **
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: Flixel 2.50 & Pausing
« Reply #8 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!

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Flixel 2.50 & Pausing
« Reply #9 on: Sun, Aug 7, 2011 »
Nice - you may want to post this to the wiki!
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

alvarocavalcanti

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
    • Loodo - A Blog about Games and Game Design
Re: Flixel 2.50 & Pausing
« Reply #10 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. :)
Alvaro Cavalcanti
Loodo - A blog about Games and Game Design
http://www.loodo.com.br

alvarocavalcanti

  • Member
  • **
  • Posts: 8
  • Karma: +0/-0
    • View Profile
    • Loodo - A Blog about Games and Game Design
Re: Flixel 2.50 & Pausing
« Reply #11 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.

:)
Alvaro Cavalcanti
Loodo - A blog about Games and Game Design
http://www.loodo.com.br

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Flixel 2.50 & Pausing
« Reply #12 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.
« Last Edit: Thu, Apr 5, 2012 by test84 »
blog, twitter, Check out my award winning game, Rot Gut:

Jeff

  • Active Member
  • ***
  • Posts: 127
  • Karma: +0/-0
    • View Profile
    • Entertainment Evolution
Re: Flixel 2.50 & Pausing
« Reply #13 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?
Please give me feedback for my latest game in progress:
Blog: Entertainment Evolution

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: Flixel 2.50 & Pausing
« Reply #14 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!
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha