On this page
  1. What you override
    1. _ready
    2. _end
    3. _suspend, _resume
    4. _update
    5. _draw
  2. What this scene lets through to whatever is underneath it
    1. updates_below
    2. draws_below
    3. input_below
    4. background
    5. gravity
    6. map
    7. camera
  3. Objects
    1. spawn
    2. destroy
    3. object_count
  4. Raycasting
    1. raycast
    2. raycast_all
  5. Navigation
    1. change
    2. push
    3. replace
    4. pop
    5. current
    6. depth

rmp::Scene

class #include <rmp/scene.h> include/rmp/scene.h:200
class Scene

A screen of the game — a main menu, a level, a pause overlay — with its own objects, map and camera. Derive from it and override the hooks you need.

The app keeps scenes on a stack: the top one runs, and the ones below it run, draw and hear input as far as updates_below, draws_below and input_below let them. The static functions — change(), push(), replace(), pop(), current(), depth() — are that stack, and work from anywhere.

What you override

_ready

virtual void _ready()

Once, when the scene enters the stack. The window exists by now, so this is where assets load.

_end

virtual void _end()

Once, when it leaves for good. Not called for a suspend — see _suspend.

It is _end and not _exit because exit() is a POSIX function, and a member called exit() in a class the user writes is a name that shadows it in a way nobody enjoys debugging.

_suspend, _resume

virtual void _suspend()
virtual void _resume()

The scene stops being updated for a while, and later starts again: a scene was pushed on top of it and came off again, or — for the scene on top, under [window] pause_unfocused — the window lost its focus and got it back. The scene is still alive and still owns everything it owned.

_update

virtual void _update(float delta)

Every frame, bottom of the stack upwards, skipping whatever the scene above freezes. delta is seconds since the last frame.

_draw

virtual void _draw()

Every frame, in SCREEN SPACE. The app closes the camera before calling this, so rmp::ui inside it cannot drift with the view — a pause menu stays where it is while the player moves. To draw in world coordinates, open the camera yourself for the few lines that need it.

What this scene lets through to whatever is underneath it

The defaults ARE a pause menu: push a scene with none of these touched and the world below freezes, stays visible, and stops receiving input. That is why a pause scene in this framework writes no policy at all.

updates_below

bool updates_below = false

The scene below keeps running

draws_below

bool draws_below = true

The scene below stays on screen

input_below

bool input_below = false

The scene below still sees input

background

Color background = BLANK

The colour the frame is cleared with. BLANK means "the theme's", which is what almost every scene wants. Only the LOWEST drawing scene's choice is used: the ones above it are drawn over what is already there.

gravity

Vector2 gravity{ 0, 980 }

The world's gravity, in units per second squared, pointing down the way everyone expects. It belongs to the scene and not to each object because direction and magnitude are a property of the world; each object then says how much of it applies to it, through Object::gravity_scale, which is 0 by default. Nothing falls until something asks to.

map

Tilemap map

The level, designed in LDtk or in Tiled (rmp/tilemap.h says which reads what). A field and not something you draw:

map = rmp::assets::load_map("world.ldtk");

and the scene draws it underneath everything, stops a solid object that moves at its solid cells, and object.bounds left empty comes to mean THE MAP'S bounds rather than the view's. An empty map costs nothing, and a menu scene simply never touches it.

That is what turns the editor from a file format into the place you design the level: you put the enemies in it and they turn up in the game.

camera

Camera camera{}

The framing. See rmp::Camera above; a scene that never touches it draws in screen units, exactly as before it existed.

Objects

spawn<T>() default-constructs T, applies the options, puts it in this scene and calls its _ready(). T only has to be default-constructible — there is no using Object::Object; and no forwarding constructor to write, which is the usual toll for this pattern. Whatever your type needs goes in its fields or in its _ready().

It returns T&, and that reference is good for the whole frame you got it in, because destruction is deferred to the end of the frame:

auto &bullet = spawn({ .position = muzzle });
bullet.velocity = aim * 900;

Kept across frames it can dangle. That is what rmp::Handle is for.

spawn

template <class T = Object> T &spawn(const ObjectOptions &options = {})

destroy

void destroy(Object &object)

Same as object.destroy(). Deferred: it stops updating and drawing at once, and the memory goes after the frame. Twice is harmless.

object_count

int object_count() const

How many live objects this scene has. Objects destroyed earlier in this frame are already not counted.

Raycasting

See the block above RayQuery in rmp/object.h for what it is for and why it walks the collision grid instead of the object list.

if (auto hit = raycast(muzzle, muzzle + aim * 400)) { ... }
auto hit = raycast({ .from = muzzle, .to = target,
                     .mask = layer::ENEMY, .ignore = self.handle() });

raycast

RayHit raycast(Vector2 from, Vector2 to) const
RayHit raycast(const RayQuery &query) const

raycast_all

int raycast_all(const RayQuery &query, std::span<RayHit> out) const

Every hit along the ray, nearest first, as many as out holds. Returns how many were written. Everything the ray passes through, for a piercing shot or a line of sight that has to know what is in the way:

std::array<rmp::RayHit, 8> hits;
const int n = raycast_all({ .from = a, .to = b }, hits);

Navigation

change

template <class T, class... A> static void change(A &&...args)
static function include/rmp/scene.h:375

Clear the stack and go. Everything on it gets _end(), top down.

push

template <class T, class... A> static void push(A &&...args)
static function include/rmp/scene.h:381

Put one on top. What was there is suspended, not ended.

replace

template <class T, class... A> static void replace(A &&...args)
static function include/rmp/scene.h:389

Swap the top one only. What is underneath is untouched and stays suspended — this is level 3 becoming level 4 without disturbing the pause menu that put you there.

pop

static void pop()
static function include/rmp/scene.h:398

Take the top one off and resume what was under it. Popping the last scene is refused with a warning rather than leaving the app with nothing to draw: on desktop that is a black window, and on iOS there is no way to get back. Call rmp::app::quit() if leaving is what you meant.

current

static Scene &current()
static function include/rmp/scene.h:401

The top of the stack. Never null while the app is running.

depth

static int depth()
static function include/rmp/scene.h:404

How many scenes are on the stack.