kaosuryoko

Fixes for Buttons When Game is Paused - Please Critique

Recommended Posts

Please bear with me, this is very likely going to be a long post.

In my quest to implement a pause system with an active ui I found myself investigating input/Pointer.js. Here I discovered the reason that my Buttons were useless when the game was paused. Specifically:

input/Pointer.js

if (this.game.paused){    return this;}

My first, and simplest fix for my use case, was simply to comment out all of the above lines. This allows me to still process Pointer callbacks when the game is paused. In my case, the UI is already set up using callbacks, but the rest of the game uses polling. So it was a convenient way to allow UI interaction without allowing other in game actions.

Offhand this method seems to have some limitations. If you're implementing first person controls your character might still spin around while you interact with the UI, though I haven't looked into it. Also if you use Pointer callbacks on any objects you want to actually pause that can cause issues.



After some more thought I came up with the following solutions:
First:

input/Pointer.js

while (i-- && !this.game.paused){     this.game.input.moveCallbacks[i].callback.call(this.game.input.moveCallbacks[i].context, this, this.x, this.y, fromClick);}

All I did was add a check if the game was paused before running any moveCallbacks. Correct me if I'm wrong, but I believe this would solve the issues with a first person style camera. Honestly though I'm not sure what all uses there are for moveCallbacks so some examples for context would be nice.

 

Next:
input/Pointer.js

else if (!this.game.paused || (this.game.paused && candidateTarget.sprite.nopause && candidateTarget.sprite.nopause == true))

This allows you to set a nopause member on any sprite. This allows you to specify exactly which objects you want to respond while the game is paused. I went ahead and added a nopause member to the sprite constructor as follows:
gameobjects/Sprite.js

this.nopause = false;

Then I can clean up the checks from before:

input/Pointer.js

else if (!this.game.paused || (this.game.paused && candidateTarget.sprite.nopause == true))

What do you guys think?

Share this post


Link to post
Share on other sites

this is a really interesting idea, its been sometime that I wanted this sort of behavior

 

I was playing with the ideas, and in my case I needed to update some more things:

 

 

 

Game.js (line 823) I passed the timestep for me to be able to update tween then game is paused if I want. This one may need some improvements, but I think its an interesting thing.

this.state.pauseUpdate(timeStep);

also, in the states I need to use this pause thing I added these lines in the pauseUpdate function

this.game.input.update();this.tweens.update(timeStep);

Pointer.js (line 444) 

/*if (this.game.paused){    return this;}*/

Pointer.js (line 457)

if (this.targetObject !== null && (!this.game.paused || this.targetObject.noPause) && this.targetObject.isDragged === true)

Pointer.js (line 523)

if (currentNode.validForInput(highestInputPriorityID, highestRenderOrderID, false) && (!this.game.paused || currentNode.sprite.noPause))

Pointer.js (line 542)

if (this.targetObject && (!this.game.paused || this.targetObject.sprite.activeOnPause))

Pointer.js (line 548)

else if(!this.game.paused || candidateTarget.sprite.noPause)

with all these changes I was able to use in a button the variable "noPause" to make the button work in the game paused.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.