melonjs/melonJS — pull request #242 by swmuron (2013-07-15 02:45:05+00:00)
Title: Ticket 159

Covers everything in #159 except for the `me.ScreenObject.onUpdateFrame()` bit which I'm not even sure is strictly needed. Given that I've only played around for less than a couple weeks with the engine, I could easily be wrong.

The basics:

- stopOnBlur replaces the old functionality of pauseOnBlur.
- pauseOnBlur now pauses the game. Can work in tandem with stopOnBlur.
- resumeOnFocus unpauses the game when the game has focus
- I split the game loop per #170 comments to avoid performance issues during unpaused game loops.

The upshot of all this is that the changes shouldn't break any existing code. The default behavior will pause and stop the game on blur then resume and restart the game loop on focus. The resume and pause callbacks will still get called in those cases.

For those users that want to get a better experience out of it, they can now hook into the pause/resume function to make use of custom pause UI/functionality. By disabling resumeOnFocus, they can allow the player to resume the game at their leisure instead of immediately starting the game up again.

The only thing I'm unsure of with this pull request is around line 608 in state.js. It looks like it checks to make sure the game isn't in a loading state before stopping/pausing/resuming, but then it fires the callback and emits an event anyway. I'm not sure if that's working as intended or not. I made the assumption it wasn't as intended in my changes.

I tried to mimic code style and document any new members or functions as appropriate. If you see anything I missed or code errors let me know and I'll look into it.

I'm only working part-time on some freelance projects at the moment...if you have any suggestions for further pull requests please let me know.