- Home /
Sprite animation
Hey, i'm currently trying to develop a game made out of sprites, and i need alittle help on the sprite ¨main character¨ movement, So i was wondering if someone could try to explain how i'm supose to make the sprites change ¨animation¨ for which way i'm walking ( its a 2D game and i have spritemanager2 )
Answer by MrSplosion · Oct 15, 2011 at 06:57 PM
It's really simple you just make a big sheet with each frame of you sprite's animation. Then tile it so that only one frame is showing at a time. Then from there you just increase or decrease the offset to show the next frame.
Sorry, it's kinda hard to explain but this tutorial should get you on the right track.
Answer by SirWeeble · Dec 01, 2015 at 10:25 AM
There are a few ways to do it, but the Animator tab is the best way.
You can create a sprite sheet by selecting the import type "Sprite" then instead of "Single" select "multiple", which will let you input how you divide up your sprite sheet. It's easiest with a grid. The editor will then re-import your sprite and divided it up for you into names like "MainCharacter_0, MainCharacter_1, MainCharacter_2" automatically, corresponding with the sprite sheet.
Then, a quick way to create a new animation is to highlight and drag the numbered sprites onto your GameObject which needs the animations. That will create an Animation object in your project tab and give the GameObject an Animator. If you open the Animation tab and select the object, you can edit the new animation, swap around it's frames, etc.
You can also manually give an object an animator, and create new animations inside the Animation tab by dragging the frames into the time-slider.
Once you've got a few animations set up, you can control which conditions control which animation you need to play. So for example, you can connect your running animation to a Boolean "isRunning".
In your animation-controller script, you can use
if( characterisMoving)
{
transform.GetComponent<Animator>().SetBool("isRunning",true);
}
else
{
transform.GetComponent<Animator>().SetBool("isRunning",false);
}
and your character will play it's running animation. Set it to false, and he will stop. You can control the logic flow in the Animator tab.