Skip to content
Rodrigo Braz Monteiro edited this page Apr 1, 2018 · 4 revisions

Overview

Stages (implemented by inheriting from Halley::Stage) are the abstraction for different "screens" of a game. For example, you might have a TitleStage, a GameStage, a CreditsStage, etc. At any given time, only one stage is running on a game. The first stage is created by the Game class, and Stages can transition to new ones by calling Halley::CoreAPI::setStage (see Core API).

Methods

Constructor

You should avoid doing any major work on a Stage's constructor. This is because a Stage is typically instantiated by the previous stage, before it has a chance to deInit itself. Also note that some methods, such as getGame() and get*API won't work here.

init()

virtual void init();

The init method is called as the stage gets set as the currently active stage. At this point, the previous stage has already been deInit-ed. Use this to perform any kind of initialisation.

deInit()

virtual void deInit();

Complement to init(). Runs before the destructor.

onVariableUpdate

virtual void onVariableUpdate(Time time);

Gets called every time the variable update timeline ticks (see Main Loop). The argument time represents the time, in seconds, since the last tick, and should be used to advance any clocks.

If using the Entity Component System, you might want to update it here. This is also a good place to update the UI.

onFixedUpdate

virtual void onFixedUpdate(Time time);

Like the method above, but runs on the fixed timeline (again, see Main Loop).

onRender

virtual void onRender(RenderContext& rc) const

This method is responsible for drawing the screen when this stage is active. A Render Context is provided, see its documentation for details on how to use it to draw to the screen.

The EntityStage class

A class called Halley::EntityStage, which extends Halley::Stage, is provided for your convenience.

createWorld

std::unique_ptr<World> createWorld(String configName, std::function<std::unique_ptr<System>(String)> createFunction);

This helper method is provided by EntityStage to create an instance of a World from a config file. See the World documentation for further details. Typical usage is as follows:

#include "registry.h" // Code generated by Halley, declares createSystem()

void MyStage::init() {
	// Creates a world based on assets_src/config/stages/my_stage.yaml
	world = createWorld("stages/my_stage", createSystem);
}
Clone this wiki locally