|
JNGL
Easy to use cross-platform 2D game library
|
Active state of the game, e.g. a menu or the game itself. More...
#include <jngl/work.hpp>
Public Member Functions | |
| virtual void | onBackEvent () |
Gets called on Android's "back" gesture or when the Esc key is pressed. | |
| virtual void | onQuitEvent () |
| Gets called when the user closes the main window or quit() has been called. | |
| virtual void | onControllerBack () |
| Gets called when the "Back" button is pressed on any connected controller (Android only) | |
| virtual void | onPauseEvent () |
| Gets called when the main window loses focus or the app is put in the background. | |
| virtual void | onLoad () |
| Gets called when the Work is activated by the main loop. | |
| virtual void | onUnload () |
| Gets called when the Work is deactivated by the main loop. | |
| virtual void | onToggleFullscreen () |
Gets called when the user pressed Alt + Enter | |
| virtual bool | supportsScreenSize (Vec2 screenSize) const |
| Gets asked by JNGL whether this Scene could be shown with screenSize instead of letter-boxing. | |
Public Member Functions inherited from Job | |
| virtual void | step ()=0 |
| Advance the game logic. | |
| virtual void | draw () const =0 |
| Draw the game state. | |
| virtual void | onFileDrop (const std::filesystem::path &) |
| Called when a file has been dropped onto the window. | |
| virtual void | onControllersChanged () |
| Whenever the return value of jngl::getConnectedControllers would change, this method gets called. | |
| virtual void | onScreenSizeChanged () |
| Gets called after the return value of jngl::getScreenSize() has changed, see jngl::Scene::supportsScreenSize() | |
| Job ()=default | |
| Does nothing. | |
| Job (const Job &)=default | |
| Copy constructor. | |
| Job & | operator= (const Job &)=default |
| Copy assignment. | |
| Job (Job &&)=default | |
| Move constructor. | |
| Job & | operator= (Job &&)=default |
| Move assignment. | |
| virtual | ~Job () |
| Does nothing. | |
|
virtual |
Gets called on Android's "back" gesture or when the Esc key is pressed.
Calls quit() by default, so exits the game. It's a good idea that you would only use the default behavior in the main menu though. While in-game you normally would switch to a pause menu. In the pause menu onBackEvent() would go to the main menu's Work.
Example:
|
virtual |
Gets called when the user closes the main window or quit() has been called.
To continue with the main loop, call cancelQuit(). For example if you want to switch to a pause menu instead of exiting the game:
Ctrl+C (SIGINT) calls forceQuit() with exitcode 130 instead and does not invoke this. Reimplemented in Fade.
|
virtual |
Gets called when the "Back" button is pressed on any connected controller (Android only)
As the TV remote is registered as a controller this is important to handle Back on the TV remote. Most likely you won't need to overwrite this though, as it calls onBackEvent() by default and having Android's "Back" button behave the same as "Back" on the TV remote is a good idea.
|
virtual |
Gets called when the main window loses focus or the app is put in the background.
On iOS and Android this will happen when the user switches to another app. As the main loop continues to run you might want to pause the game if necessary.
|
virtual |
Gets called when the Work is activated by the main loop.
Reimplemented in WorkFactory.
|
virtual |
Gets called when the user pressed Alt + Enter
By default it switches between fullscreen and windowed mode. You can overwrite this if you want to do something else, e.g. if you want to disable toggling fullscreen mode because you need the keyboard shortcut for something else.
|
virtual |
Gets asked by JNGL whether this Scene could be shown with screenSize instead of letter-boxing.
The canvas keeps the size it had when the window was created, even when the window changes its shape later on, e.g. because the user rotated their phone or resized the window. Instead JNGL scales it to fit into the window, letter-boxing it where the shapes differ. The same happens when AppParameters::minAspectRatio or maxAspectRatio didn't allow the canvas to fill the whole window in the first place.
Before each step in which the window doesn't have that shape, JNGL asks the active Scene whether it can handle the screen size that would fill the whole window instead. If it can't and the window's aspect ratio is outside of AppParameters::minAspectRatio and maxAspectRatio, JNGL asks again for the screen size which is letter-boxed to them, i.e. what the canvas would be if the window had been created with its current size. When this returns true, jngl::getScreenSize() will return screenSize from then on and Job::onScreenSizeChanged() gets called. Once it returns false for both, e.g. because another Scene became active which doesn't override this method, the canvas goes back to its original size.
screenSize is the size of the canvas in actual pixels divided by the scale factor that AppParameters::scaleFactor returns for it. If that hasn't been set, jngl::getScaleFactor() is used, as it doesn't change once the window has been created.
Returns false by default.
Reimplemented in Fade.