How to: Create your first animation
Creating an animation
- Create the sprites that you want to use as frames for your animation, as described in "Create a Sprite".
- Open the "Sprite editor" window. ("Window > RetroKit > Sprite Editor")
- Open the "Animations" window, by toggling the "Animations" button.
- Click "New" in the "Animations" window.
- Select the sprite you want to add to the animation in the "Sprite Properties" window.
- Click "Add Active Sprite".
- Repeat steps 5 and 6 for all the sprites you want to add, in the order you want.
- Set the animation speed to the value you want. (You can check a preview by toggling the "Preview" button to see the result.)
Using the sprite animation in a scene
RetroKit generates native Unity animation clips, which you can use as normal.
By default, the generated animation clips are located in Assets/RetroKit/Graphics/Animations.
If you assign the animation clip to a game object, an Animator asset is automatically created and stored in the same folder as the animation clips. It's recommended you move the animator asset to a more suitable folder, so that it's not stored next to generated content.
Create an animation set
Creating an animation set is a way to group related animations together. For example, you could group all animations for a player character together or those of a certain type of enemy. Using animation sets makes switching between animations very easy, more on that later.
- Create the animations you want to group together (For example, Player_Jump, Player_Run, etc.), as described in "Create an animation"
- Open the "Sprite Editor" window. ("Window > RetroKit > Sprite Editor")
- Open the "Animation Sets" window, by toggling the "Animation Sets" button.
- Make sure the "Animations" window is open.
- Click "New" in the "Animation Sets" window to create a new animation set.
- Select an animation you want to add to the group in the "Animations" window.
- Click "Add Active Sprite Animation" to add the animation to the set.
- Repeat steps 5 and 6 for all the animations you want to add to the set.
Using the sprite animation set in a scene
RetroKit generates native Unity animator assets for each animation set. The generated animators contain the added animations and the transitions needed to switch between all the animations.
You can use the Animator Controller as normal and change the active animation by changing the ActiveAnimation parameter.
However, to make this easier (and safer), RetroKit generates an enum file and extension method on the animator for each animation set.
Here's an example snippet of a MonoBehaviour script to demonstrate how that works for an animation set called "Player" containing an animation called "PlayerJump".
using UnityEngine;
public class Player : MonoBehaviour
{
private Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
animator.SetActiveAnimation(AnimationsPlayer.PlayerJump);
}
}
}