# rmp::Scene

> A screen of the game -- a main menu, a level, a pause overlay -- with its own objects, `map` and `camera`.

Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html

class `#include <rmp/scene.h>` [include/rmp/scene.h:200](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L200-L423)

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()

hook [include/rmp/scene.h:219](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L219)

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

### `_end`

virtual void _end()

hook [include/rmp/scene.h:226](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L226)

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()

hook [include/rmp/scene.h:232](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L232)

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)

hook [include/rmp/scene.h:237](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L237)

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

### `_draw`

virtual void _draw()

hook [include/rmp/scene.h:243](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L243)

Every frame, in SCREEN SPACE. The app closes the camera before calling this, so [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) 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

field [include/rmp/scene.h:252](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L252)

The scene below keeps running

### `draws_below`

bool draws_below = true

field [include/rmp/scene.h:253](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L253)

The scene below stays on screen

### `input_below`

bool input_below = false

field [include/rmp/scene.h:254](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L254)

The scene below still sees input

### `background`

Color background = BLANK

field [include/rmp/scene.h:259](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L259)

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 }

field [include/rmp/scene.h:266](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L266)

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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#gravity_scale), which is 0 by default. Nothing falls until something asks to.

### `map`

Tilemap map

field [include/rmp/scene.h:280](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L280)

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

```cpp
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{}

field [include/rmp/scene.h:284](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L284)

The framing. See [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html) 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:

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

Kept across frames it can dangle. That is what [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) is for.

### `spawn`

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

function [include/rmp/scene.h:303](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L303-L319)

### `destroy`

void destroy(Object &object)

function [include/rmp/scene.h:323](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L323)

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

function [include/rmp/scene.h:327](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L327)

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.

```cpp
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

function [include/rmp/scene.h:339](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L339)

### `raycast_all`

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

function [include/rmp/scene.h:348](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L348)

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:

```cpp
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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L375-L378)

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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L381-L384)

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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L389-L392)

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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L398)

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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) if leaving is what you meant.

### `current`

static Scene &current()

static function [include/rmp/scene.h:401](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L401)

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

### `depth`

static int depth()

static function [include/rmp/scene.h:404](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L404)

How many scenes are on the stack.
