|
| | Action ()=default |
| | Action (const Action &)=default |
| auto | operator= (const Action &) -> Action &=default |
| virtual | ~Action ()=default |
| | Action (Action &&other) noexcept=default |
| auto | operator= (Action &&other) noexcept -> Action &=default |
| auto | operator== (const Action &other) const -> bool |
| | Action (std::string name) |
| | Action (std::string name, float duration) |
| | Action (std::string name, float duration, const th::Bezier &bezierCurve, float initialDelay, float endingDelay) |
| auto | update (float dt) -> void |
| | Universal update function that handles calling init, update, and end at the right time.
|
| virtual auto | init () -> void |
| | Virtual function that is called once, when the Action is first starting up.
|
| virtual auto | execute () -> void |
| | Virtual function that is called every frame to change a game object.
|
| virtual auto | end () -> void |
| | Virtual function that is called once, when an Action is finished executing.
|
| virtual auto | ActionShowMenu () -> void |
| | Displays a window in imgui.
|
| virtual auto | render () const -> void |
| | Function used to draw things to screen, useful for things such as debug drawing.
|
| auto | shouldRemove () const -> bool |
| auto | getOwner () const -> Entity * |
| auto | setOwner (Entity *newObject) -> void |
| auto | getHasInitialized () const -> bool |
| auto | getHasExecuted () const -> bool |
| auto | getHasEnded () const -> bool |
| auto | isPaused () const -> bool |
| auto | setPaused (bool newState) -> void |
| auto | isBlocking () const -> bool |
| auto | setBlocking (bool newState) -> void |
| auto | setInitialDelay (float delay) -> void |
| auto | setEndingDelay (float delay) -> void |
| auto | getName () -> std::string |
| | Function used for displaying info about what an Action does.
|
| auto | getCompletionPercentage () const -> float |
| | Function used to see how much the action has completed.
|
At its core, an Action is simply something that changes a variable over a period of time. Actions can move an entity around, make things fade in or out, or even facilitate some gameplay. They are very versatile, but typically very specific. Actions almost always do just 1 thing. Actions are also very self-sufficient; All you need to do is create it and add it to an Entity, and it will handle the rest.
Actions Example
Making and using an Action is very simple. You just create the Action and pass it along to an Entity / ActionList.
For every Action, at minimum you will always need 1 thing: the end goal.
Let's say, for example, that we are a Component and want to apply a MoveToPointAction to our parent Entity. For this specific Action, our end goal will be a point (specifically a Point2D).
Point2D destination = {600,300,0,1};
An action that moves an object to a specific point in the game world.
Definition MoveToPointAction.h:32
You can also pass in the variables directly instead of defining them beforehand.
Actions have a lot of extra parameters for fine-tuning (like total duration and initial delay, as examples). But you don't have to mess with those if you don't want to. Some of the more interesting ones will be explained in the "Advanced Actions" section.
To add these Actions to an entity, you have a few methods. The easiest option is to use the addAction function (slower but safe) or the << operator (faster but unsafe)
auto parent = getEntityParent();
parent.addAction(action);
parent << otherAction;
Alternatively, you can get the ActionList component itself and add directly to it
auto actionList = parent->getComponent<
ActionList>(cActionList);
Component that stores all actions currently affecting the parent entity.
Definition ActionList.h:30
auto pushBack(const std::unique_ptr< Action > &newAction) -> void
Definition ActionList.cpp:159
All at once, adding an Action can look something like this:
Creating New Actions
However, there will be times where the Action you want hasn't been made yet, in which case you will have to create it yourself. Don't worry though, the NewActionStub is mostly filled out for you already. You will just need to update a few things.
I would recommend having your file open to the side of these instructions to make following along easier
- Member variables
- "startingValue" and "endingValue": You will want to update these two to be of the type that you want to change. E.g. if you are changing a color, then you want to make them colors, if you are changing a position then you want to make them points.
- "component": You should also update the "component" pointer to be the type of whatever component stores the variable you want to change. This is primarily so you don't need to get the component every execute frame.
- Constructors
- You'll want to update the constructors to interact with your ending value and have the right Action name
- The three constructors that are already provided are the ones that I think are most useful, but you can implement more or less if you want.
- Execution Code
- note: init and execute have some code inside of them provided for you. Across both of them, you have the bare minimum required for an Action to work properly.
- init: This function is called before the execute loop. It's useful for initiating variables and setting stuff up.
- execute: This function is called across multiple frames and handles the actual changing of the Entity.
- exit: This function is called after execute, right before the Action is fully finished and marked for deletion. This function is a bit more specific, so you'll only need to put code in here if necessary.
Advanced Actions
This section is about the extra variables inside of Actions.
Delays
These just delay the activation of certain function calls by some time.
- initialDelay: This delays when "init" is called.
- endingDelay: This delays when "end" is called, after the Action has finished executing.
Paused
This one is pretty simple. If an Action is paused, then it simply doesn't update. Once it is unpaused, it will continue updating as normal.
Blocking
If an Action is blocking, then it stops the activation of all Actions after it in the ActionList. I've included an example as to better explain it.
Let's say this is our ActionList
Order: 0 1 2
An action that changes the color (and alpha) of a sprite.
Definition ChangeColorAction.h:27
Normally, when ActionList updates, it will update all of these in order. However, if ChangeColorAction is blocking, then once it is updated, then ActionList stops updating. That means RotateAction (and any other potential Actions after it) WILL NOT UPDATE until ChangeColorAction is done.
Curve
Curves are currently WIP and not very user-friendly right now. Don't worry about it for now, just know that it handles easing. Examples of easing can be found at https://easings.net/