# rmp::behavior::Collectible

> A coin, a key, a heart.

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

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

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

| Field | Type | Default | What it is |
|---|---|---|---|
| `collected_by` | `unsigned` | `0xFFFFFFFFu` | The layers that pick it up |
| `sound` | `std::string` |  | Played by [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) when it is picked up; "" = silent |
| `magnet` | `float` | `0` | Within this many units of a collector it flies to it; 0 = never |
| `magnet_speed` | `float` | `360` | How fast, in units per second |
| `vanish_seconds` | `float` | `0.25f` | How long it takes to go; 0 = at once |
| `on_collect` | `Callback<Object &, Object &>` |  | (the pickup, who picked it up), once |
| `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. |

### `collected`

bool collected() const

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

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

### `from`

static Collectible from(const MapObject &object)

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

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.
