# rmp::behavior::TopDown

> Eight directions, and the sprite chosen from the one you are facing.

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

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

struct TopDown

Eight directions, and the sprite chosen from the one you are facing.

The eight-way movement is free and correct because [`rmp::input::vector()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#vector) normalises: going diagonally is NOT 41 % faster, which is the bug in half the raylib tutorials on the internet.

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

## Fields

| Field | Type | Default | What it is |
|---|---|---|---|
| `speed` | `float` | `220` | Design units per second |
| `eight_way` | `bool` | `true` | False = four directions only |
| `acceleration` | `float` | `0` | 0 = instant, which is what nearly all 2D wants |
| `idle` | `std::string` | `"idle"` | THE ANIMATION NAMES ARE YOURS: they are the tags in your .aseprite, and "idle" and "walk" are only the defaults, not a convention imposed on you. The tag actually chosen is "<walk>_<suffix>" if the sheet has it and "<walk>" with flip_x if it does not, so a two-, four- or eight-direction sheet all work with nothing configured. `idle` is played as it is, with no suffix. With no sheet on the object's sprite only flip_x is set, and an empty name plays nothing. THE ART FACES RIGHT. flip_x is set while facing left, to mirror the frames that have no direction of their own — `walk` without a suffix, `idle`, or a sprite with no sheet — so those must be drawn facing east. A tag with a suffix is drawn for its direction and plays unflipped. |
| `walk` | `std::string` | `"walk"` | THE ANIMATION NAMES ARE YOURS: they are the tags in your .aseprite, and "idle" and "walk" are only the defaults, not a convention imposed on you. The tag actually chosen is "<walk>_<suffix>" if the sheet has it and "<walk>" with flip_x if it does not, so a two-, four- or eight-direction sheet all work with nothing configured. `idle` is played as it is, with no suffix. With no sheet on the object's sprite only flip_x is set, and an empty name plays nothing. THE ART FACES RIGHT. flip_x is set while facing left, to mirror the frames that have no direction of their own — `walk` without a suffix, `idle`, or a sprite with no sheet — so those must be drawn facing east. A tag with a suffix is drawn for its direction and plays unflipped. |
| `suffixes` | `std::array<std::string, 8>` | `{ "e", "ne", "n", "nw", "w", "sw", "s", "se" }` | THE ANIMATION NAMES ARE YOURS: they are the tags in your .aseprite, and "idle" and "walk" are only the defaults, not a convention imposed on you. The tag actually chosen is "<walk>_<suffix>" if the sheet has it and "<walk>" with flip_x if it does not, so a two-, four- or eight-direction sheet all work with nothing configured. `idle` is played as it is, with no suffix. With no sheet on the object's sprite only flip_x is set, and an empty name plays nothing. THE ART FACES RIGHT. flip_x is set while facing left, to mirror the frames that have no direction of their own — `walk` without a suffix, `idle`, or a sprite with no sheet — so those must be drawn facing east. A tag with a suffix is drawn for its direction and plays unflipped. |
| `left` | `std::string` |  | Which actions move it. Empty = the move_* actions that come as standard. |
| `right` | `std::string` |  | Which actions move it. Empty = the move_* actions that come as standard. |
| `up` | `std::string` |  | Which actions move it. Empty = the move_* actions that come as standard. |
| `down` | `std::string` |  | Which actions move it. Empty = the move_* actions that come as standard. |
| `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. |

### `direction`

Vector2 direction() const

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

The last non-zero direction, normalised. What a game reads to fire a weapon the way the character is looking.

### `sector`

int sector() const

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

Which of the eight sectors `ours.facing` is in, as an index into `suffixes`.
