1
Support / Re: Moving AnimatedSprite
« on: March 01, 2013, 01:58:59 am »
I got the solution! I was using GetKeyDown, instead of GetKey, I was going to delete this post, but I will let it here in case it someone's trouble.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
public class TutorialAnimController : MonoBehaviour
{
tk2dAnimatedSprite anim;
// Use this for initialization
void Start () {
anim = GetComponent<tk2dAnimatedSprite>();
}
bool walking = false;
float movespeed = 0.1f;
void HitCompleteDelegate(tk2dAnimatedSprite sprite, int clipId)
{
if (walking)
{
anim.Play("walk");
}
else
{
anim.Play("idle");
}
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.A))
{
anim.Play("hit");
anim.animationCompleteDelegate = HitCompleteDelegate;
this.transform.position = new Vector3(this.transform.position.x-movespeed, this.transform.position.y, 0);
}
if (Input.GetKeyDown(KeyCode.D))
{
anim.Play("walk");
anim.animationCompleteDelegate = null;
walking = true;
this.transform.position = new Vector3(this.transform.position.x+movespeed, this.transform.position.y, 0);
}
if (Input.GetKeyDown(KeyCode.W))
{
anim.Play("idle");
anim.animationCompleteDelegate = null;
walking = false;
}
}
}