- Home /
change sprite animation in ex2d ?
Hi , how can i change sprite animation in ex2d component ? i want to change animation from walk to jump when touching screen of android device can any one help me ? thanks
Answer by Anxo · Nov 21, 2011 at 06:59 PM
I dont know anything about ex2d but what you want to look for is what texture it is using and change that. Sprites are just sequences of images, change the sequence and you change the animation.
So if you are using sprite sheets and you have a sheet called "Characterwalk.jpg" and you have one called "CharacterJump.jpg" you would create var for each and then replace them at the appropriate time.
var characterWalk : Texture2D; var characterJump : Texture2;
then call them into your material when you need him to jump.
Answer by nantas · Nov 22, 2011 at 03:58 PM
First you add exSpriteAnimation Component to your gameObject with exSprite, and put your sprite animations into the list of the component.
Then whenever you want to change sprite animation, use this code in your script that has a reference to the sprite.
var sprite: exSprite;
sprite.spanim.Play ("hero_run_01");
The "spanim" is a property of exSprite class, you can always use it to get the sprite animation component. For more details, check out ex2D script reference:
Answer by mahdi68 · Nov 23, 2011 at 11:17 AM
this is my code : var spAnim:exSpriteAnimation; function Start() { spAnim = GetComponent("exSpriteAnimation"); spAnim.Play("ninja_run");
}
Answer by neva · Feb 13, 2013 at 09:21 PM
Hello, I'm having trouble with exactly the same situation, but unfortunately the script above doesn't work for me.Fist of all, I'm using Unity 4.0.1f2. I added two animations to the Sprite Animation Object, but when I try to call the Start function again in order to play the second animation, the first animation (in the first if part) freezes and it stays like that forever. The code gets in the "else if" part but doesn't play the second animation. I'd appreciate it v much if you could help me. Thanks
public var spAnim: exSpriteAnimation;
function Start() {
if (something){
spAnim.Play("name_of_the_1st_animation");
}
else if(somethingelse){
spAnim.Play("name_of_the_2nd_animation");
}
Your answer
Follow this Question
Related Questions
Animation with Transparency Floats Above Ground 1 Answer
What is wrong with my EX2D code? 1 Answer
How do you integrate huge sprite sheets? 1 Answer
Animation not playing until i move character. 0 Answers
Best way to equip a 2D character? 1 Answer