JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Work Class Reference

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.
 
- 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.
 
 Job ()=default
 Does nothing.
 
 Job (const Job &)=default
 Copy constructor.
 
Joboperator= (const Job &)=default
 Copy assignment.
 
 Job (Job &&)=default
 Move constructor.
 
Joboperator= (Job &&)=default
 Move assignment.
 
virtual ~Job ()
 Does nothing.
 

Detailed Description

Active state of the game, e.g. a menu or the game itself.

Definition at line 13 of file work.hpp.

Inheritance diagram for Work:
[legend]
Collaboration diagram for Work:
[legend]

Member Function Documentation

◆ onBackEvent()

virtual void onBackEvent ( )
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:

class MainMenu : public jngl::Work {
// default implementation of onBackEvent which quits the game
};
class PauseMenu : public jngl::Work {
void onBackEvent() override {
jngl::setWork<MainMenu>();
}
};
class Game : public jngl::Work {
void onBackEvent() override {
jngl::setWork<PauseMenu>();
}
};
Active state of the game, e.g. a menu or the game itself.
Definition work.hpp:13

◆ onQuitEvent()

virtual void onQuitEvent ( )
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:

class Game : public jngl::Work {
void onQuitEvent() {
jngl::setWork<PauseMenu>();
}
};
void cancelQuit()
Undo quit() or ignore a quit event caused by the user closing the main window.

◆ onControllerBack()

virtual void onControllerBack ( )
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.

◆ onPauseEvent()

virtual void onPauseEvent ( )
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.

◆ onLoad()

virtual void onLoad ( )
virtual

Gets called when the Work is activated by the main loop.

Reimplemented in WorkFactory.


The documentation for this class was generated from the following file: