The traditional method of animation involved hand-drawing many images, each slightly different, which displayed quickly frame-by-frame to give the appearance of movement. For computer game animation, the term Sprite Sheet is given to the image file that contains one or more sequences of sprite frames. Unity provides tools to breakup individual sprite images in large sprite sheet files, so that individual frames, or sub-sequences of frames can be used to create Animation Clips that can become States in Animator Controller State Machines. In this recipe, we'll import and break up an open source monster sprite sheet into three animation clips for Idle, Attack, and Death that looks as shown:
For all the recipes in this chapter, we have prepared the sprite images you need in folder 1362_03_05
. Many thanks to Rosswet Mobile for making these sprites available as Open Source at: http://www.rosswet.com/wp/?p=156.
To create an animation from a sprite sheet of frame-by-frame animation images, follow these steps:
monster1
.monster1
selected in the Project panel, change its Sprite mode to Multiple in the Inspector, then open the Sprite Editor panel by clicking button Sprite Editor.Animations
.0
, 0
, 0
), and drag your monster-animator into this GameObject.monster1
in the Project panel (in its expanded view), and select and drag the first 5 frames (frames 0-4) into the Animation panel. Change the sample rate to 12 (since this animation was created to run at 12-frames per second).Unity's Sprite Editor knows about sprite sheets, and once the correct grid size has been entered it treats the items in each grid square inside the sprite sheet image as an individual image, or frame, of the animation. You selected sub-sequences of sprite animation frames and added them into several Animation Clips. You had added an Animation Controller to your GameObject, and so each Animation Clip appears as a state in the Animation Controller State Machine.
You can now repeat the process, creating an Animation Clip monster-attack with frames 8-12, and a third clip monster-death with frames 15-21. You would then create Triggers and Transitions to make the monster GameObject transition into the appropriate states as the game is played.
Learn more about the Unity Sprite Editor from the Unity video tutorials at https://unity3d.com/learn/tutorials/modules/beginner/2d/sprite-editor.
3.145.179.85