pgzero
pgzero copied to clipboard
Add on_exit() hook
This update adds support for an on_exit() hook.
Overview of changes contained in this pull request:
- Support for users to define an
on_exit()function which is called after the game loop is exited. This function can be defined with 0 parameters or 1 parameter (error_status). - Support for users to define an
on_enter()function which is called before the game loop is entered. - Existing
exit()function has been changed to use the common exiting path.
Notes:
- Felt using the name
on_exit()seemed better thanon_before_exit(). - Added
on_enter()support for symmetry. - Documentation still needs to be updated for this. I can add that to this pull request or open a new issue to track it.
- Could only find a few test cases for
PGZeroGame(intest_event_dispatch.py). If you would like test cases for these changes, I can add them to this pull request or open a new issue to track them.
System details (used for testing):
- os: windows 10
- python: 3.5.0
- pygame: 1.9.4
- pgzero: master branch at ef963beaa22db89cb011695e96587bb268cbec2a
- numpy: 1.15.4
Resolves #51.
It looks like this issue has stalled. I've seen someone else asking for this feature on reddit.
I don't see much need for a status code for most users. Perhaps there is someone that it may be helpful to, but it think a simple on_exit() would be sufficient.
I'm happy to have a go at making the changes and creating a pull-request, if that will help.