![]() |
ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
|
Split your game into self-contained parts: a menu, a level, or a game over screen, ect.
Use this when you are structuring a new part of your game that has its own entities, systems, and rules.
Include: Imago/Engine/Scene.hpp
A scene is one self-contained part of your game. Each scene has its own entities, systems, and events. Only one scene runs at a time. When the player moves from the main menu into a level , the game switches from one scene to another.
You create one scene by writing a class that inherits from Scene. In it, you fill in the on_load method which runs when the scene starts. on_load ought to: define the scene’s starting entities, register its systems, and subscribe to its events. After that, the engine runs the current active scene’s every frame until you switch to another scene.
A scene class describes the kind of scene and its rules. Keep game logic in systems, not in the scene class itself.
You should only ever write code inside of on_load or on_unload. If you do not need on_unload it can be safely deleted but on_load must be defined.
Register every scene with the game at once, before calling run(), and give each one a name. Set firstScene to the scene the game should start in.
From then on, every scene is referred to by its name given here, not its type.
on_load is the only place you set a scene up. Use the scene’s members:
| Member | Use it to | See |
|---|---|---|
| _nexus | Create entities and bind components | Entities and Components |
| _scheduler | Register systems | Systems |
| _broadcaster | Subscribe to events | Events |
Everything you bind is in place before the scene’s first frame.
on_unload runs just before the scene ends. Most scenes will not need it because the scene’s entities, systems, and subscriptions are all removed automatically. Use it only for work outside the scene.
Scenes are switched by name from inside a system. See {game notifications}
| Name | What it is | Notes |
|---|---|---|
| game.register_scene<T>(name) | Registers scene class T under name | Call before run(); each name once |
| config.firstScene | The name of the scene the game starts in | Must be a registered name |
| on_load() | Your scene's setup | Required |
| on_unload() | Runs when your scene ends | Optional |
| _nexus, _scheduler, _broadcaster | The scene's entities, systems, and events | Available in on_load and on_unload |