IndependentAnimator and Animating Something Not Connected to an Entity - UQdeco2800/2021-studio-6 GitHub Wiki

This is a combined guide and documenation to the IndependentAnimator class and how to use it.

Overview:

The purpose of the IndependentAnimator is to assit in animating atlas files ingame. While the AnimationRenderComponent can achieve this as well, that then requires a entity to attach the component to. The trouble is when trying to animate something without a specific entity where creating and handling an entity is either unneccessary or not an option. As such, IndependentAnimator circumvents this issue by removing the need for an entity and supplimenting that functionality with additional functions.

Documentation:

The three main functions of the IndependentAnimator are the pairs of setters and getters for position, scale and camera tracking. When attached to an entity, AnimationRenderComponent can get the position and scale from the entity itself. However, by removing the entity, there is more freedom in the settings of the animator.

public void setPositions(float x, float y) / public float[] getPositions()

These two functions are used to set/get the x and y coordinates of where the animation should be player. What these coordinates are used in relation to is set in the camera tracking.

public void setScale(float x, float y) / public float[] getScale()

This pair of functions interacts and sets the x and y scale of the animation. You can in theory set the scale to a certain effect using the scale of an existing entity, thus still allowing some interaction between IndependentAnimator and entities.

public void setCamera(boolean to)

This sets whether or not the animation positions should be calculated in reference to the camera or not (by scene instead). True sets it to follow the player, false for the scene. Following the player allows for use in things like the interface, menu or player-related actions (i.e. attacking in some cases). Following the scene allows it to animate non-entities in the environment (i.e. moving parts in the background that are not associated with entities).

Additionally, you must ensure that the IndependentAnimator gets disposed of properly when neccessary (normally level change). While AnimationRenderComponent is attached to an entity and gets disposed with it at the same time, IndependentAnimator's should be disposed of directly as it will not be called elsewhere.

Guide:

Setup -

In a component or class related to whatever the animation is, the IndependentAnimator should first be created. When doing so, you should give the constructor the filepath to the animations atlas file. It is at this point that you must also add the individual animations to the Animator through .addAnimation() as how AnimationRenderComponent currently works. After this, it is advised to set the position, scale and camera tracking of the Animator so that it doesn't use the default values. These can also be set later (for instance, setting the position later can be used to change the animation location dynamically). After this, you should create and call a separate function in this class to set the animations. This function calls the next class to be discussed, the AnimationController, to set the IndependentAnimator. It is advised for this functional call to be separate to help avoid issues in attempting to start animations before assets are loaded in.

AnimationController -

Similar to how AnimationRenderComponent works, IndependentAnimator should be used in conjuncture with a new AnimationController class, like how PlayerMovementAnimationController and PlayerHealthAnimationController work. That is, an entirely new class file should be made for the controller. Each controller should only manage a single atlas file and makes use of events/triggers to start and stop animations. The main difference with the way AnimationControllers work with IndependentAnimator compared to AnimationRender is that IndependentAnimator controllers require their reference to IndependentAnimator to be set elsewhere. This is normally done through a setter() function that is called outstide of the AnimationController, wherever the IndependentAnimator is first created. This can be set to pass a component, the IndependentAnimator itself or the function can directly access the relevant component if a getter method is included and the controller can access the component.

General Steps:

  1. Create IndependentAnimator in whatever component or class is related to the animation.
  2. Add atlas files and assets to be loaded ingame
  3. Add animations and set values of the IndependentAnimator (position, scale and camera tracking)
  4. Create the new AnimationController class for the associated atlas file.
  5. Create the setter in the AnimationController to get the IndependentAnimator from wherever it was created
  6. Add events and triggers for the animations to the AnimationController
  7. Add dispose method to the AnimationController to dispose of the IndependentAnimator and whatever else