A scene is designed to be a single screen in your game. For example, you might have a loading Scene, a menu Scene, etc.
Scenes are subclasses of a class template called Scene<T>. To create your Scene class you must do the following:
Scene<T> but pass your class up as T (Search for the 'Curiously Recurring Template Pattern' for more info)Window* and passes it to the parent constructorvoid load() methodHere's an example:
class MyScene : public Scene<MyScene> {
public:
MyScene(Window* window):
Scene<MyScene>(window) {}
void load();
};
You can then register the Scene in your application's init() method:
bool init() {
scenes->register_scene<MyScene>("main");
return true;
}
Whichever Scene is registered with the name "main" is the first Scene instantiated when the application begins.
You can override the following methods in your Scene class:
activate() and deactivate() are called when you change to a different scene.
Scenes are managed by the SceneManager, which is a property of Application. The application SceneManager is accessible directly from within a scene using the scenes property.
You can make a Scene current by calling SceneManager::load_and_activate(name, behaviour, ...). This will do a number of things:
Scene is already active, it will be deactivated.SCENE_CHANGE_BEHAVIOUR_UNLOAD then the old Scene will have its unload() method called. Scene::destroy_on_unload() is true, then the old Scene will be deleted.Scene will be instantiated.Scene hasn't been loaded, its load() method will be called.Scene::activate() will be called on the new sceneYou have a lot of control over this process:
Scene ahead of time, before activating it by using SceneManager::preload(name, ...)Scene from being unloaded when deactivated.Scene from being deleted when unloaded.Scene before loading the next, or you can load the next before unloading the current Scene by passing the behaviour argument as ACTIVATION_BEHAVIOUR_UNLOAD_FIRST, or ACTIVATION_BEHAVIOUR_UNLOAD_AFTERThis means that you can (for example) create render pipelines that remain active even
once the Scene has been deactivated, and use that to implement transitions etc.
You can also pass arbitrary arguments to Scenes on activation. You can access these arguments by using the get_load_arg<T>(index) function from within the Scene. When calling load_and_activate, or preload you can pass the arguments as variadic args for access. This is useful if you want to (for example) pass the level number to the game scene.