On this page
  1. Fields
    1. alive
    2. jitter_amount

rmp::behavior::Spawner

behavior #include <rmp/behavior.h> include/rmp/behavior.h:388
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

FieldTypeDefaultWhat it is
every_secondsfloat0

One of these two, not both

every_distancefloat0

Units travelled between spawns; wins if both are set

jitterfloat0

+/- this much, uniformly

max_aliveint0

0 = no limit, and it is a cap on the LIVE ones

trackHandle<Object>

Where "travelled" is measured from. Empty = this object's own position.

on_spawnCallback<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.

oursstruct { … }

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

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

A fresh random amount between -jitter and +jitter from rmp::random::range, or 0 when jitter is 0 or less or not a finite number: what each interval after the first is moved by.