Hello Guest

Author Topic: Moving AnimatedSprite  (Read 3681 times)

rafaelmqueiroz

  • Newbie
  • *
  • Posts: 2
    • View Profile
Moving AnimatedSprite
« on: March 01, 2013, 01:13:00 am »
I know that there's two or three posts about it, but I read, did almost the same thing the guys were doing,
and still need to press again, to make my character move, if I just keep the button pressed it will be still.
Can someone help me with that? Here is my code:

Code: [Select]
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;
        }


}


}

rafaelmqueiroz

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Moving AnimatedSprite
« Reply #1 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.