[Unity3D basic tutorial] Unity tutorial for beginners (3): Learn about Sprite and Animation in Native 2D by making Flappy Bird.

Source: Internet
Author: User

Author: Wang Xuan Yi, source: http://www.cnblogs.com/neverdie/Reprinted, Please keep this statement. If you like this article, click [recommendation ]. Thank you!

Introduction

The last time we talked about MonoBehaviour's past and present, we learned that every GameObjec in the game is controlled by a script. This time we started to use Sprite in Native 2D in Unity, and use Animation to make Sprite dynamic.

In the following blogs, I will use Flappy Bird to explain how to use various components in Unity. The source code of the Project is here: Unity Flappy Bird. Welcome to Fork and Star.

How to Create a Sprite

To create a Sprite, follow these steps:

Note the following when creating a Sprite:

  • Sprite is added to a GameObject as an attribute of the Sprite Renderer component.
  • The Sorting Layer attribute in Sprite Renderer allows you to set the Sprite rendering priority.
  • SpriteRenderer uses Texture in the Sprite attribute, but uses the Shader in the Material, the defaultSprites/DefaultThis type of Shader ignores the light, whileSprites/DiffuseSuch Shader will not ignore the light. If you set Material to None, you will find that the Sprite cannot be displayed because you have not colored the Sprite.
Sprite detailed settings

SpriteSheet: as the name suggests, it refers to putting multiple Sprite into one image. Generally, an animation is placed in an image. The game engine splits the SpriteSheet and plays each frame of the SpriteSheet in turn to form an animation sequence. For example:

 

The corresponding values include 1, 2, and 3. Let's talk about the precautions separately.

 

How to add an Animation for Sprite

There are two ways to create an animation. One is what we mentioned above. we drag several Sprite in SpriteSheet to the Scene view at the same time.

In the Scene view, select the GameObject for which you want to Add an Animation. In the Animation view, click Add Curve to play the various attributes of the GameObject.

In Unity, Animation is a broad concept and is not limited to frame Animation. It includes the dynamic changes of various attributes of GameObject. If you click Add Curve, you will see the following interface:

In the above picture, you can find that the Animation can be performed from Position to Color, from Rotation to Sprite, because the Animation in Unity is actually adding a change curve. Instead of the Animation we generally understand.

Another explanation is the difference between Animator and Animation. If you want to move an Animation, you must have two Assest resources: Animation Clip and Animator Controller. In a Project, the following forms are shown:

Animator is an Animation state machine that controls the switching between animations. We will talk about its usage in later blogs. = W =

Detailed settings of Animation

In the above figure, I marked some important cases in the Animation view in the figure.

Summary

In general, editing an Animation in Unity's Animation is very convenient, and there is a feeling of a bird rifle in the past when editing an Animation using a Cocos2d-x. However, the support for Sprite itself is still a bit unpleasant, because we are still not used to the Unity Sino-German coordinate system when doing 2D, we often get rid of Pixel as the most important measurement Unit when we make 2D games. After Unity is changed to Unit, we feel overwhelmed, however, this is a change in the way 3D engines think.

References

Official SpriteRenderer documentation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.