# rmp::behavior::Spawner

> Produces objects every N seconds, or every N units TRAVELLED.

Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html

behavior `#include <rmp/behavior.h>` [include/rmp/behavior.h:388](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L388-L431)

struct Spawner

Produces objects every N seconds, or every N units TRAVELLED.

By distance is not the same as a Timer, and the difference is the whole reason this is not one: in an endless runner the speed climbs, so "every two seconds" puts the obstacles further and further apart and the game gets EASIER the faster you go, which is the opposite of the intention.

Added to an object with `add<rmp::behavior::Spawner>()`; the framework calls its `_update` with the object it is on.

## Fields

| Field | Type | Default | What it is |
|---|---|---|---|
| `every_seconds` | `float` | `0` | One of these two, not both |
| `every_distance` | `float` | `0` | Units travelled between spawns; wins if both are set |
| `jitter` | `float` | `0` | +/- this much, uniformly |
| `max_alive` | `int` | `0` | 0 = no limit, and it is a cap on the LIVE ones |
| `track` | `Handle<Object>` |  | Where "travelled" is measured from. Empty = this object's own position. |
| `on_spawn` | `Callback<Scene &, Vector2>` |  | Makes what is spawned, given the scene and where `track` (or this object) is now. Every object it adds counts towards `max_alive`. Empty = the Spawner does nothing. |
| `ours` | `struct { … }` |  | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. |

### `alive`

int alive() const

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

How many of the objects it made are still alive RIGHT NOW. It goes down when they die, which is the whole difference between a cap and a quota.

### `jitter_amount`

float jitter_amount() const

function [include/rmp/behavior.h:430](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L430)

A fresh random amount between -jitter and +jitter from [`rmp::random::range`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#range), or 0 when `jitter` is 0 or less or not a finite number: what each interval after the first is moved by.
