On this page
  1. Fields
    1. direction
    2. sector

rmp::behavior::TopDown

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

FieldTypeDefaultWhat it is
speedfloat220

Design units per second

eight_waybooltrue

False = four directions only

accelerationfloat0

0 = instant, which is what nearly all 2D wants

idlestd::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.

walkstd::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.

suffixesstd::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.

leftstd::string

Which actions move it. Empty = the move_* actions that come as standard.

upstd::string

Which actions move it. Empty = the move_* actions that come as standard.

downstd::string

Which actions move it. Empty = the move_* actions that come as standard.

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.

direction

Vector2 direction() const

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

sector

int sector() const

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