Learn about sprite,animation in native 2D by making Flappy Bird

Source: Internet
Author: User


  Welcome to Unity Learning,Unity training ,UnityEnterprise TrainingEducation Area, there are manyu3d Resources,u3d Training Video,u3d Tutorials,U3d Frequently Asked questions,u3d Project Source code, the "Dog Planing Learning Network" Unity's Ultimate Academy, dedicated to building the industry unity3d Training , learning the first brand.
  

Introduction
This time we started to native the sprite in Unity 2D and use animation to get the sprite moving.
In the next few blogs, I will be doing a Flappy Bird to explain the use of components in unity, the source of the project is here: Unity Flappy Bird. You are welcome to fork and star.
How to create a sprite
To create a Sprite, follow these steps
Add a sprite resource by dragging a picture to a folder in Project view.
Modify the properties of the sprite resource and, if it is Spritesheet, split it in the Sprite editor.
Drag a sprite resource into the scene view, or hold down the CTRL key while you drag several pictures in Spritesheet to the scene view, which creates an animation at the same time.
In the process of creating a Sprite, please note that:
A sprite is added to a gameobject as a property of the sprite renderer component.
The sorting Layer property in the sprite renderer allows you to set the priority of the sprite being rendered.
Spriterenderer uses the texture in the Sprite property, but uses the shader (shader) in material, which is selected by default Sprites/default
This shader is ignored by the light, and Sprites/diffuseThis shader will not ignore the light. If you set material to none, you will find that the sprite cannot be displayed because you are not coloring the sprite.
Detailed settings for Sprite
  

Spritesheet: As the name implies, it means putting multiple sprites in a single picture. In general, a frame animation is placed in a picture, the game engine will split the Spritesheet, take turns to play each frame in the Spritesheet, forming an animation sequence. Such as:
  

Corresponds to 1, 2, 33 points, I say the notes separately
When the sprite mode is single, you can set the pivot point of the sprite in inspector, and if you have used cocos2d-x before, you will know that this pivot Point is the equivalent of anchor point in Cocos2d-x. In scene, we will use this pivot point as the center to rotate the sprite, translate the transform settings. If you are using Spritesheet, you can set pivot settings for each sprite in the sprite editor.
Since the units are unit in unity, in order to guarantee 3D and 2D consistency, we also use unit as the unit of measure in 2D games. Pixel to units a few of this conversion ratio. For example, a sprite picture with a width of 100, displayed in scene with a length of 1Unit.
In the sprite editor can be automatic and grid two forms of cutting, in general, Automatic has been able to better solve the problem, once encountered we need a few sprite picture size consistent, you can use Grid (GRID) segmentation, To limit the size of each sprite.
How to add a animation to a sprite
There are two ways to create animations, one we've said above, to drag several sprites from Spritesheet to the scene view at the same time.
The other is in the scene view, select the gameobject you want to animate, and in Animation view, click Add curve to animate the various properties of the Gameobject.
In unity, animation is a relatively broad concept and is not limited to frame animations. It includes dynamic changes in the various properties of the Gameobject. If you click on Add curve, you will see this interface:
  

In the above picture you can see that from position to color, from rotation to Sprite, it is possible to animation, because animation in unity is actually adding a change curve. Rather than the animation we generally understand.
Another thing to explain is the difference between animator and animation, to note that if you want to lay a animation move up, then you must need two assest resources, respectively, animation clip and animator controller two kinds of resources. In project, it is the following representation:
  

Animator is an animated state machine that controls the switching between the various animation. In the following blog we will talk about its use. =w=
Detailed settings for animation
  

In the diagram above, I have highlighted some of the important cases in the animation view.
KeyFrames are the turning point of the animation, where you set some of the sprite's points of change, or a turning point for position data.
An animated event can be set at a frame of the animation, and the so-called animated event that can be set in this frame is the non-overloaded function of all the script components on this gameobject (that is, functions such as removing onupdate,start). After the animation event is set. You'll notice that every time the animation loops over, the function is called at that frame.
Add a change curve, as stated above, to transform any property.
Sample refers to the sampling, that is, in the 1s set how many frames, in the figure we can see the 1s interval of 12 dashed lines, which means that in this second, we set 12 frames to adjust the animation. Note that the sample here is not related to the refresh frame rate that we set for the game.
Summarize
In general, it's very handy to edit animations in Unity's animation, and it's kind of niaoqianghuanpao when you used cocos2d-x to edit animations. But the support of the sprite itself is a bit uncomfortable, because do 2D, or not used to unity in the German coordinate system, because the production of 2D games we often killed the pixel pixel as the most important unit of measurement, Unity replaced unit units, feel a little overwhelmed, But this is a change in the way the 3D engine thinks.
Resources
For more information on Spriterenderer's official documentation, visit the Dog planing Learning Network, Unity's Ultimate Academy http://edu.gopedu.com


Statement: This document comes from the "Dog Planing Learning Network" Community-unity Extreme College, is a self-published Unity3d study articles, if anything violates your relevant interests, please communicate with the official, we will deal with the real-time.


Understanding sprite,animation in native 2D by making Flappy Bird

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.