On this page
  1. Fields
    1. collected
    2. from

rmp::behavior::Collectible

behavior #include <rmp/behavior.h> include/rmp/behavior.h:674
struct Collectible

A coin, a key, a heart. Touched by an object on a layer of collected_by, it calls on_collect, plays its sound, stops colliding and vanishes — it rises, grows and fades for vanish_seconds — and is destroyed. Within magnet of a collector it flies to it first. What a coin is worth is the game's: on_collect is where it counts.

From the editor: "magnet" (Float).

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

Fields

FieldTypeDefaultWhat it is
collected_byunsigned0xFFFFFFFFu

The layers that pick it up

soundstd::string

Played by rmp::audio when it is picked up; "" = silent

magnetfloat0

Within this many units of a collector it flies to it; 0 = never

magnet_speedfloat360

How fast, in units per second

vanish_secondsfloat0.25f

How long it takes to go; 0 = at once

on_collectCallback<Object &, Object &>

(the pickup, who picked it up), once

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.

collected

bool collected() const

Whether it has been picked up: from then on it only vanishes.

from

static Collectible from(const MapObject &object)

A Collectible with the fields the map's entity has by these names — magnet — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file.