Preparing sprite animation
- Game Development course
- Beginner
- Lesson 59/83
- 4 min
Learn to slice multiple sprites for sequential playback.
Sprite animation setup and Slice
In 2D games, character animations are typically authored using Spritesheet files packing multiple frames into one image. After setting Sprite Mode to Multiple, the Slice operation is executed in the Sprite Editor.
// Loading all sliced sub-frames from a spritesheet
Sprite[] walkFrames = Resources.LoadAll<Sprite>("HeroWalkSheet");Slicing divides the graphic into pieces based on uniform grids or pixel boundaries.
Frames and Animation Flow
Sliced frames appear as child sub-assets under the main asset in the Project window. Cycling through these frames sequentially produces classic frame-by-frame 2D animation.
// Displaying the initial animation frame
Sprite currentFrame = walkFrames[0];
sr.sprite = currentFrame;Keeping sprite pivot points consistent across frames (e.g. at character feet) prevents jitter.
Practice Print animation frame count
Assign 8 to totalFrames and "Run" to animName. Print Animation: Run | Frames: 8 to the console.
Starter code
using System;
class Program
{
static void Main()
{
// totalFrames ve animName değerlerini tanımlayıp yazdır
}
}Sample solution
using System;
class Program
{
static void Main()
{
int totalFrames = 8;
string animName = "Run";
Console.WriteLine("Animation: " + animName + " | Frames: " + totalFrames);
}
}Expected output
Animation: Run | Frames: 8
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the operation of dividing a single Spritesheet into individual animation frames called?
- Extrude
- Rigging
- Slice Correct answer
- Baking
Explanation: Slice divides frames within a spritesheet into separate individual sprite assets.
2 Load multiple sprite frames
Sprite[] frames = Resources.____<Sprite>("KnightRun");
Sprite[] frames = Resources.LoadAll<Sprite>("KnightRun");
Explanation: The LoadAll method is used to retrieve all sub-sprite frames from a spritesheet as an array.
3 Animation setup terms
| Term | Meaning |
|---|---|
Spritesheet |
Sheet packing multiple animation frames |
Sprite Editor |
Tool to slice graphics and set pivots |
Slice |
Dividing an image into separate frames |
Frame |
Single visual moment in an animation |