Pausing everything but the pause screen?[SOLVED]


(VanderJamesHum) #1

Before I go spending lots of time figuring this out myself I’d like to see if anyone here has implemented this or could at least point me in a good direction.


I’m creating a pause screen/inventory that when opened should stop updating all the entities in the world. You can change weapons/armour/game options etc and when you return to the game all the changed variables get saved and entities continue to update.


How would this best be achieved? I know I can’t stop super.update() on the world because it will pause the Inventory/options menu as well. Could I perhaps stop all the entity updates other than the Inventory? Or have a separate world for the menu and switch between them? The latter option I don’t like the sound of at all, because for one I would like the game world to still be visible when messing around in the pause menu. Could I perhaps add an IF statement to all the entities, saying something like " if not paused, update, otherwise stop update", and the world itself doesn’t stop updating?


In the end though I don’t mind having a DARK SOULS kind of inventory but I would still appreciate any help :slight_smile:



(David Williams) #2

Typically what I do is have a static boolean PAUSED and check for paused din all of my entities updates.

if(SomeClass.PAUSED) return;
else
{
    //all other code
}

(VanderJamesHum) #3

Thanks a lot it works like a charm! As always the features I predict will take weeks to get working turn out to be very simple and straightforward with flashpunk.


EDIT::::::::::::::::::::::::::: Maybe not as straight forward after all. I discovered that tweens and particles, (and also spritemaps) will continue to update even if the entity they are attached to is not updating, so one must set the “active” property of the tween or particle to FALSE while the game is paused and TRUE when unpaused.


(Justin Wolf) #4

Note: This only applies if you’re using the non-SWC’d version of FP. If you aren’t, then you’ll have to create your own GameEntity.as that extends Entity.as to help with overriding some of FP’s class functions.

I know this is solved, but just wanted to throw in how I do it by controlling the World’s update while still being able to update certain entities, such as buttons and other UI. Just throw a static variable on a Globals class named “paused”. Then in your world’s update function:

Your Game’s World:

override public function update():void
{
     if (!Global.paused) super.update();
}

If the world doesn’t update, then nor do any of its contained entities. So, in order to update certain entities, I created an updateOnPause public variable on Entity.as. When you’re setting up your class that extends Entity, simply set updateOnPause to true in the constructor if you wish for it to update while the game is paused. And if true, when the Entity is added to the world, it is added to a vector that is manually updated in your game’s world class.

Entity.as

override public function added():void
{
     if (updateOnPause) Global.pauseUpdates.push(this);
}

override public function removed():void
{
     if (updateOnPause) FP.remove(Global.pauseUpdates, this);
}

Your Game’s World:

override public function update():void
{
     if (!Global.paused) super.update();
     else 
     {
          for each (var e:Entity in Global.pauseUpdates) 
          {
                if (e.active) e.update();
          }
     }
}

Bit more work than the above solution but this allows you to easily control which entities should be updated when the game is actually paused, when controlling pausing within your World’s update loop. As for tweens, I built in a few functions in my FP class that allows me to pause and resume all tweens (Greensock tweens, I don’t use FP tweens) when the game is paused or resumed. And particles, you’ve already got it figured out, just simply set active to false on the emitter.


(Ultima2876) #5

I’d recommend making your own GameEntity class that derives from Entity and provides a base class for all of your in-game entities to add features like that - main reason being that you can easily add lots of tweaks without worrying about changes in future versions of FlashPunk (especially now that it’s mainly an SWC).

Also be careful about using Greensock’s tween library - they’ve recently changed their licensing so that you need a paid license on games that earn revenue through sponsorship and mobile release.


(Justin Wolf) #6

Yeah, I haven’t updated to the SWC version as of yet. But you’re right, definitely will have to be making my own classes eventually.

And are they? Dang… that is bad news. Wonder if there’s just a one-time licensing fee you can pay? I’m looking through their licensing section and it doesn’t really mention anything about sponsorship, unless I’m completely missing it. Under their Standard “No Charge” License it says:

Usage in 100% free apps, games, sites, and other software even if you charge a fee to develop these products

Does this not apply to flash games? They’re 100% free to the end user. I’ll keep looking through it though to see if I’m missing something. It also states:

Our paid license is only necessary in software that you create using our products that is sold to multiple end users.

And in the actual terms of use, it states:

You may use the code at no charge in commercial or non-commercial apps, web sites, games, components, and other software as long as end users are not charged a fee of any kind to use your product or gain access to any part of it. If your client pays you a one-time fee to create the site/product, that’s perfectly fine and qualifies under the “no charge” license. If end users are charged a usage/access/license fee, please sign up for a “Business Green” Club GreenSock membership which comes with a comprehensive commercial license. See http://www.greensock.com/club/ for details.

Mobile releases (paid ones, at least), however are obviously a different story, and would require the license. But flash games sold under the sponsorship method I don’t see any issue with, according to the licensing page and terms of use page.


(Ultima2876) #7

Ah, looks like you’re right - my mistake! I saw a topic a little while ago on FGL regarding it and it looks like they were talking about app store and microtransactions, not sponsorship and mobile.

https://www.fgl.com/view_thread.php?thread_id=44196

EDIT: Also, just looked at your username and saw who you are. Herrow! Haha :smiley: