Unity Learning Notes-wizard set and sprite animation __unity3d

Source: Internet
Author: User
Tags assert

2d game, the operation of the wizard needs, is often two points:

1, Static Wizard: General to do background display and so on

2, Sprite Animation: Frame animation, skeletal animation, etc.

Statement: Following the unity of the operation, based on Unity3d 4.3.4, I am a beginner unity, no other version.

First, the wizard file import

Method 1:

If the project is set to 2D when it is created, then when you copy the picture file to the Assert directory, the texture type of the image defaults to Sprite. The following figure:


Method 2:

If the project is not 2D, or do not want to change the project settings, you can manually set the TextureType to Sprite, click Apply to confirm. The effect is exactly the same as Method 1.

second, the original unity of the Elves animation

1. Large image decomposition into small map:

Sometimes the resources found are in the form of a wizard atlas, as follows:

This is a loading atlas. After dragging the picture into an assert related directory, modify Spritemode to multiple and set the wizard to a collection of multiple sprites instead of single. Then click Spriteeditor to open the wizard editor.

The following figure:

Of course, you can also open the wizard editor first,:window> Spriteeditor in the main menu.

Slice is a slice, remember JS in the operation of the array, as if there is this function.

Type has two values to choose from: Automatic and grid. Grid is based on the mesh to the segmentation, automatic is more stupid. In general, there is a gap between the small figure in the plot, and then use the automatic, basically do not have to set, you can guarantee not to cut bad. As follows:

Finally, click Apply to determine. Then you'll find that there are a lot of small graphs that appear below the atlas:

Then these small pictures are all selected, drag and drop directly into the scene inside, generated anim animation files. It can't be any simpler. However, the animation produced by this, are frame animation.


2. Frame Animation:

Unity if you need to make frame animation, the native editor is supported. Window->animation, open the animation editor. Drag the first frame you want to animate into scene, and then select the wizard, as shown in the following figure:

Click on the Addcurve,transform, Spriterenderer, animator these 3 actually correspond to the 3 class attributes of the wizard in the Inspector respectively. Like what:

Of course, this is a spoof of mine. Scale is responsible for scaling changes, Sprite is responsible for switching sprite pictures. Then it becomes a frame of animation. When you add keyframes, there is a addkey in the right key menu in the timeline. Select a frame and modify the property in Inspector. The animation is too arbitrary to make.

Wizard Atlas and frame animation in three and 2Dtoolkit

1. The production of Atlas

In Project, Create>tk2d>spritecollection. The atlas is the form of a file that is made into prefab. After you set the file save parameters,

Open the editor from here.

Then drag the picture you want to package and drop it to the left of the editor. The following figure:

Then you change the parameters of each wizard. The most needed attention is anchor and Collidertype. such as this wavy ground, collider type, I set it to polygon polygon, and then this convex must be checked. The convex polygon is set to be used in collision detection. Click on the collider at the bottom of the editor to edit the collision area yourself.

The operation in the edit, the lower right corner is a hint:

Finally click on the top right-hand corner of the commit completed.

2. Frame animation

It's still in project, Create>tk2d>spriteanimation. After you create the file, open the editor:

Clip is the frame animation.

Play is used for animating or pausing. WrapMode is the animation of the playback mode, is the loop playback, or fragment loops. Reverse is the reverse of the animation, that is, the inverted broadcast. Collection and Sprite are used to set the sprite set and the specific sprite for the current frame, respectively. If you want to delete the current frame, click Delete. Trigger is the trigger event of frame animation, because it is just beginning to learn, has not started to make specific game, this temporarily useless.

Finally, click on the top right-hand corner of the commit to complete the modification.

3. Create Sprite Animation

Create->tk2d->sprite Withanimator

The wizard is set to the first frame of the animation, allowing you to select the Sheep animation in the animation set test that you just made. You can see it in the game.

Of course, you can also create Tk2d->sprite, and then add Tk2dspriteanimator.


The result is the same as creating the Spritewithanimator directly.

 

four, in the tk2d to toggle the animation to play

As follows:

Using Unityengine;
Using System.Collections;

public class Sheep:monobehaviour {

	private tk2dspriteanimator M_anim;
	private bool M_bchange = false;

	Use this for initialization
	void Start () {
		M_anim = getcomponent<tk2dspriteanimator> ();
		Print ("initialization");
	
	Update is called once per frame
	void Update () {
		if (input.getmousebuttondown (0)) {
			print ("left-click"); 
  
   if (m_bchange) {
				m_anim.play ("eat");
			} else {
				m_anim.play ("Bian");
			}
			M_bchange =!m_bchange;
		}
	}

  

Bind to the sheep Sprite, and then this same animation set has two animation eat and Bian, through the left mouse button click, turn to play.

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.