Class Actor

class Actor : public ISaveable

The Actor class represents an Actor in the game’s world.

See also

Direction

Public Functions

Actor() = default

Empty constructor.

Actor(const std::string &fileName)

Constructor that takes a path to the .ractor file.

Actor(std::unique_ptr<TileSet> tileSet, Vector2 atlasPos, std::string tileSetSource)

Constructor that takes a TileSet, the atlas position of the tile to use, and the path to the TileSet.

Actor(const ActorBin &bin)

Constructor that takes an ActorBin binary structure

virtual json dumpJson() override

Dump this Actor’s data to a nlohmann::json object.

void unload() const

Unload routine. The UnloadTexture function will called here.

void update()

Update routine.

void draw() const

Draw routine.

std::string getSourcePath() const

Get the source file’s path for this Actor.

Vector2 getPosition() const

Get this actor’s position in the world.

void setPosition(Vector2 newPosition)

Set this Actor’s position.

void setTilePosition(Vector2 newPosition, Vector2 tileSize)

Set Actor position relative to a tile in the world.

Vector2 getTilePosition() const

Get this Actor’s tile position.

void moveByVelocity(Vector2 velocity)

Move the Actor using a velocity vector.

Rectangle getRect() const

Get the bounding box of this Actor.

TileSet &getTileSet() const

Get a reference to this Actor’s TileSet.

int getCurrentFrame() const

Get the current frame of this actor.

inline void resetAnimation()

Reset the animation back to frame 0.

Direction getAnimationDirection() const

Get the current direction of this actor.

Vector2 getCurrentAnimationAtlas() const

Get the current animation atlas of this actor.

Rectangle getCurrentAnimationRectangle() const

Get the current animation rectangle of this actor.

Vector2 getAnimationAtlasByIdx(int frameIndex) const

Get an atlas of this actor by frame index.

void setAnimationFrame(int frameIndex)

Set the current frame.

int getAnimationCount() const

Get the current size of the animation in the direction.

void setTileSet(const std::string &newTileSetSource)

Set this Actor’s TileSet using a path to the tileset file.

Rectangle getCollisionRect(Vector2 velocity) const

Get the collision rectangle of this Actor if it was moved by the velocity vector

Rectangle getCollisionRect() const

Get the collision Rectangle of this Actor

Vector2 getCollisionCenter() const

Get collision center point.

void addAnimationFrame(Direction id, Vector2 atlasPos)

Add a frame in the chosen animation. The frame represents an atlas tile from this Actor’s TileSet.

void removeAnimationFrame(Direction id, int frameIndex)

Remove a frame in the chosen animation, specified by an index.

void setAnimationFrame(Direction id, int frameIndex, Vector2 atlasTile)

Change a frame in the chosen animation to another atlas tile from the TileSet.

void addAnimationFrames(Direction id, const std::vector<std::vector<int>> &frames)

Add multiple frames to the chosen animation.

void playAnimation(Direction id)

Temporarily play an animation

bool isTempAnimationPlaying()

Check whether a temporary animation is playing

void changeAnimation(Direction id)

Change the Actor’s current animation and play it.

std::string getTileSetSource() const

Get the path of the used TileSet.

std::array<std::vector<Vector2>, 8> getAnimationsRaw() const

Get an array of this Actor’s animations

std::vector<Vector2> getAnimationRaw(Direction id) const

Get a specific animation

void setCollisionRect(Rectangle rect)

Set the Actor’s collision Rectangle

bool hasInteractable()

Whether this Actor has an Interactable.

void setHasInteractable(bool value)

Set the ‘ownsInteractable’ flag.

Interactable *getInteractable()

Get a pointer to this Actor’s Interactable.

void setInteractableFromPath(const std::string &interPath)

Add an Interactable using an interactable file.

Public Members

std::function<void(int)> onFrameChanged

The callback when the current frame changes.