Easy Way to Pause the Game (While Dialogue is Shown)?

Weasel8778

  • Posts: 236
I want to have a sign in my game that a player can read. When he interacts with it, the game should pause (eg moving platforms will stop moving, the player cannot move, etc) while he reads the sign. When he clicked off it, the game should continue.

I realise that this would be possible if I changed every single behaviour to check against a 'Is Paused?' global attribute, but that isn't really viable at this stage... Is there no easier way to do this?

The only idea I have is that when you interact with the sign and the dialogue comes up, then the game is paused using the current pause function. However, the pause menu is now changed to simply show the unpause button, which now reads 'close dialogue'. For example, the behaviour would be like:

if(interact with sign)
{
show dialogue
pause
remove dialogue
}

So as soon as they click the 'remove dialogue' button (the masked 'unpause game' button), they wouldn't know any different, right? I just don't know if this is possible.

« Last Edit: July 20, 2011, 10:26:54 am by Weasel8778 »

Darkhog

  • Posts: 1243
No, unfortunately it isn't. You'll have to make "Is Paused" thing.

There are no impossible things. There is only lack of skills.
Don't click this if your computer has less than 641 kilobytes of RAM.
Stencyl stencyling stencylish stencylers :D

Weasel8778

  • Posts: 236
No, unfortunately it isn't. You'll have to make "Is Paused" thing.

I just updated my first post; is the following not possible?

"The only idea I have is that when you interact with the sign and the dialogue comes up, then the game is paused using the current pause function. However, the pause menu is now changed to simply show the unpause button, which now reads 'close dialogue'. They wouldn't know any different, right? I just don't know if this is possible."

Hectate

  • *
  • Posts: 4643
Currently, the Flixel pause menu is not easily accessible to alter.

One thing I've seen done is using Flixel's "timescale" to make the game go into slow motion - slow enough to not be noticed that it is still moving.

That'd require a code block since it's a call to a Flixel function ot exposed in the engine.

FlxG.timeScale is the specific property.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Epic428

  • Posts: 1118
It is possible to do this, yes. However, you will need to know AS3 & Flixel's API in order to do this.

I have been able to create a custom pause screen before, the problem though, is that you lose out on any API calls specifically related to SW, like actors, scenes, etc. So knowing AS3 & Flixel will allow you to implement sprites, mouse events, etc above the game.

I imagine that with a bit of tweaking, the engine could be modified to allow all of this to work using actors, etc., but that would require more time and effort than we can afford today.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

Weasel8778

  • Posts: 236
Thanks for the replies. My AS3 isn't strong and I've never used Flixel's API so I'll probably just implement the dialogue without the pausing.

dineyin

  • Posts: 110
One thing I've seen done is using Flixel's "timescale" to make the game go into slow motion - slow enough to not be noticed that it is still moving.

That'd require a code block since it's a call to a Flixel function ot exposed in the engine.

FlxG.timeScale is the specific property.

Has anyone actually tried that one out? it seems pretty clever and simple. I'll have to try this one tonight when I'm home

Sunflower

  • Posts: 591
Wait, is this "IsPaused" thing really necessary?
I mean, what about disabling behaviors?

At the beginning, you create a Global Attribute where all behaviors to be activated/deactivated during pause are listed (naturally, you would update them at the initial scene). Then, you make a function "disable behaviors enlisted in [ list ]" or whatever you want to call it, and similar "enable behaviors enlisted in [ list ]". Of course, as long as none of behaviors contains things you would like to keep activated and things you would like to stop (like updating the position of player/platform etc.), but even if there are such ones, there shouldn't be many of them.

Yes, making this whole list is quite a lot of work, but I think that it's still better than "IsPaused", unless it's about memory; but I don't think that bunch of behaviors names is that scary (also, it gives you better control on what you want to stop and what would you like to keep active). At least, that's the most sensible solution I can think of right now.

« Last Edit: July 21, 2011, 04:48:12 am by Sunflower »

Joe

  • *
  • Posts: 2480
Hectate might be able to clarify, but I don't think slowing down the Flixel timestep would have any effect on the physics engine. I wonder if the Actors and their collision bodies could get out of sync.

As for disabling Behaviors, you have to be careful about doing that, too. I doubt that timed tasks, for example, would be paused.

Given the current system, I think the cleanest way would really be to have each Behavior receive an "is paused" message.

Hectate

  • *
  • Posts: 4643
One thing I've seen done is using Flixel's "timescale" to make the game go into slow motion - slow enough to not be noticed that it is still moving.

That'd require a code block since it's a call to a Flixel function ot exposed in the engine.

FlxG.timeScale is the specific property.

Has anyone actually tried that one out? it seems pretty clever and simple. I'll have to try this one tonight when I'm home

Well I'd heard someone else got it to work after I suggested it I recall Jon being surprised that it worked with Box2D's physics simulations.

I just tested myself. A falling block moves at half speed. I had two, one with a Y speed constantly set to 10 and no gravity effect. The other a physics object only with scene gravity set to 10. Side by side they both fell and slowed down whenever timescale was reduced (and sped back up when I released the key which reset it).
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Hectate

  • *
  • Posts: 4643
Oh, don't set it to zero. Freezes game. Permanent pause state, lol.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Weasel8778

  • Posts: 236
      Wait, is this "IsPaused" thing really necessary?
      I mean, what about disabling behaviors?

      At the beginning, you create a Global Attribute where all behaviors to be activated/deactivated during pause are listed (naturally, you would update them at the initial scene). Then, you make a function "disable behaviors enlisted in [ list ]" or whatever you want to call it, and similar "enable behaviors enlisted in [ list ]". Of course, as long as none of behaviors contains things you would like to keep activated
and things you would like to stop (like updating the position of player/platform etc.), but even if there are such ones, there shouldn't be many of them.

Yes, making this whole list is quite a lot of work, but I think that it's still better than "IsPaused", unless it's about memory; but I don't think that bunch of behaviors names is that scary (also, it gives you better control on what you want to stop and what would you like to keep active). At least, that's the most sensible solution I can think of right now.[/list][/list]

But this wouldn't work because deactivating will make it lose its current position in the behaviour, as well as losing all saved attributes. Definitely not an option.

dineyin

  • Posts: 110
One thing I've seen done is using Flixel's "timescale" to make the game go into slow motion - slow enough to not be noticed that it is still moving.

That'd require a code block since it's a call to a Flixel function ot exposed in the engine.

FlxG.timeScale is the specific property.

Has anyone actually tried that one out? it seems pretty clever and simple. I'll have to try this one tonight when I'm home

Well I'd heard someone else got it to work after I suggested it I recall Jon being surprised that it worked with Box2D's physics simulations.

I just tested myself. A falling block moves at half speed. I had two, one with a Y speed constantly set to 10 and no gravity effect. The other a physics object only with scene gravity set to 10. Side by side they both fell and slowed down whenever timescale was reduced (and sped back up when I released the key which reset it).

I just tested it in my game (FlxG.timeScale = 0.001) and it works remarkably well at slowing down the game and appear paused, it even stops timed tasks as you would expect them to. Sound (or background music) continues playing appropriately. the main problem is that it also stops detecting user input, it seems like it only checks each frame (which makes sense), but if you have to use a button to unpause the game then you have to wait for a frame to pass before it will respond.

Weasel8778

  • Posts: 236
One thing I've seen done is using Flixel's "timescale" to make the game go into slow motion - slow enough to not be noticed that it is still moving.

That'd require a code block since it's a call to a Flixel function ot exposed in the engine.

FlxG.timeScale is the specific property.

Has anyone actually tried that one out? it seems pretty clever and simple. I'll have to try this one tonight when I'm home

Well I'd heard someone else got it to work after I suggested it I recall Jon being surprised that it worked with Box2D's physics simulations.

I just tested myself. A falling block moves at half speed. I had two, one with a Y speed constantly set to 10 and no gravity effect. The other a physics object only with scene gravity set to 10. Side by side they both fell and slowed down whenever timescale was reduced (and sped back up when I released the key which reset it).

I just tested it in my game (FlxG.timeScale = 0.001) and it works remarkably well at slowing down the game and appear paused, it even stops timed tasks as you would expect them to. Sound (or background music) continues playing appropriately. the main problem is that it also stops detecting user input, it seems like it only checks each frame (which makes sense), but if you have to use a button to unpause the game then you have to wait for a frame to pass before it will respond.

So how long would the delay be after clicking the button?

dineyin

  • Posts: 110
first, It seems like it doesn't have an input buffer (so it doesn't remember the key that was pressed unless it happens exactly when the frame switches) so you have to check for "key is down" as opposed to "key was pressed".
As for timing, for me frames were happening about every 6 seconds, but if the frame was coming up right after the user pressed the key, then it would happen right away. so pretty much pure chance. There might be a way to use flash directly to detect for input and then reset the Flixel time step to be normal, but I don't have time to test that right now.