Tuesday, September 16, 2014

How to make a sprite for 2D Games

Sprite not only supports the object to move but also some 2D animations like explosion, projectile fly, etc.

Prefabs can be reused in the game with just drugging it into "Hierarchy". Here I will show how to make a sprite prefab for Unity.

1. Create a Sprite:
            Choose "GameObject" -> "Create Other" -> "Sprite" as the image bellow shows:

2. Rename the object.
3. Choose the image imported in the "assets" then change the "texture type" to "Sprite(2D\uGUI)":

4. drug the image onto the sprite object and change the z value to "-1", then it will show on the screen.

Some times we also need to use sprite sheet to implement animation like explosion. Here are the steps to make that.


1. Choose the explosion image, change its texture type into Sprite and also modify its  Sprite Mode to "Multiple":

2. Click "Sprite Editor" and slice the sprite sheet:

3. Create a Sprite and name it as "explosion". Add the material to "explosion":

4. Click "Window"-> "Animation"->"Add Curve"->"Sprite Renderer"->"Sprite":



5. Drag the other slices into the Animation Editor:

6. Modify the animation attributes as the images shows:

7. Play and we will see the animation. However, when the animation finishes playing, the object stays at the last image. We want to delete the object, so we need to modify the animation.
  • Add a script to the object:
  • Add an event on the animation and choose the function:

8. Run the game and after animation completes, the object is destroyed.

No comments:

Post a Comment