Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility method to determine if Engine is paused or not #750

Closed
jedeen opened this issue Jan 24, 2017 · 6 comments
Closed

Add utility method to determine if Engine is paused or not #750

jedeen opened this issue Jan 24, 2017 · 6 comments
Labels
feature Label applied to new feature requests good first issue good for people new to open source and Excalibur

Comments

@jedeen
Copy link
Member

jedeen commented Jan 24, 2017

Context

Currently, you can stop/start (i.e. pause/resume) a game with Engine.start() and Engine.stop(). However, in order to implement pause logic, you need to manage your own boolean:

var paused = false;
game.on('p', () => {
   if (!paused) {
      game.stop();
   } else {
      game.start();
   }
   paused != paused;
});

Proposal

The Engine already has a private _hasStarted variable that appears to be maintaining, but not exposing, this status.

It would be helpful to have an isStopped() or isPaused() method to return the current state of the game, so the above code could be simplified to:

game.on('p', () => {
   if (!game.isPaused()) {
      game.stop();
   } else {
      game.start();
   }
});
@jedeen jedeen added feature Label applied to new feature requests good first issue good for people new to open source and Excalibur labels Jan 24, 2017
@kamranayub
Copy link
Member

If you implement your game UI as all HTML this also works really well, since if the game is stopped no updates/processing will happen but HTML will work fine.

@jedeen jedeen added this to the vNext milestone Jan 25, 2017
@SurajGoel
Copy link
Contributor

Can I take this ?

@eonarheim
Copy link
Member

@SurajGoel For sure! Please do, let us know if you need any assisstance :)

@SurajGoel
Copy link
Contributor

@eonarheim Sorry, didn't see your post. On it now, will update you soon.

@SurajGoel
Copy link
Contributor

SurajGoel commented Feb 27, 2017

@eonarheim How should I write a unit test for this ? A simple idea :- Maybe run the engine first, check the status, stop the engine, check the status again. And should I put the test in Utility Functions test suite ?

@jedeen
Copy link
Member Author

jedeen commented Mar 1, 2017

@SurajGoel Sounds like a good way to do it! You'll probably want to test that it can be un-paused as well.

This is Engine functionality, so I'd recommend putting the test in EngineSpec.ts

Now that I'm thinking about it, this is more of a test of the Engine.start() and Engine.stop() methods. @excaliburjs/core-contributors, what do you think?

SurajGoel added a commit to SurajGoel/Excalibur that referenced this issue Mar 3, 2017
- Added a function isPaused to check the running status of Engine into Engine.ts

Resolves: excaliburjs#750
eonarheim pushed a commit that referenced this issue Mar 8, 2017
Closes #750 

## Changes:

- Added a function isPaused to check the running status of Engine into Engine.ts
@jedeen jedeen modified the milestones: 0.10.0 Release, vNext Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Label applied to new feature requests good first issue good for people new to open source and Excalibur
Projects
None yet
Development

No branches or pull requests

4 participants