Hello Guest

Show Posts

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.


Messages - weinster

Pages: [1]
1
Support / Re: Sprite Animation Issue
« on: February 01, 2013, 09:18:09 pm »
Thank you unikron!  Once i updated to 1.90 it all worked perfectly.

2
Support / Re: Sprite Animation Issue
« on: February 01, 2013, 08:25:49 pm »
Thanks unikron for replying but i have another issue.  I included the code that you suggested and unity is now reporting an error.  It says 'tk2dAnimatedSprite' does not contain a definition for 'IsPlaying'.  There is an IsInvoking that comes up and i tried using that but i get the same result of the animation constantly resetting and my character is locked in the first frame.

3
Support / Sprite Animation Issue
« on: February 01, 2013, 02:06:43 pm »
Hi,

I have read through the documentation and searched around before i posted this but have yet to find an answer that works for me.  I am having an issue with getting the my 2d Toolkit animation sprite to work properly.  It seems that i can either move my character and have the animations stick on the first frame, or my character does not move but all the animations run just fine.  Here is an abbreviated section of my code...

This one will play the animations just fine but not move the character -

Code: [Select]
using UnityEngine;
using System.Collections;

public class AnimControllerTest : MonoBehaviour {

public float runSpeed;
public float gravity;
Vector2 velocity = Vector2.zero;

tk2dAnimatedSprite anim;

void Start ()
       {
anim = GetComponent<tk2dAnimatedSprite>();
        }

void Update ()
       {

CharacterController player = GetComponent < CharacterController > ();

if (player.isGrounded)
{
velocity = new Vector2 (Input.GetAxis ("Horizontal"),0);
WalkAndRun();
}

velocity.y -= gravity * Time.deltaTime;
player.Move (velocity * Time.deltaTime);

}

void WalkAndRun ()
{
if (Input.GetKeyUp (KeyCode.RightArrow))
{
anim.Play("Idle Right");
                anim.animationCompleteDelegate = null;
}
if (Input.GetKeyUp (KeyCode.LeftArrow))
{
anim.Play("Idle Left");
                anim.animationCompleteDelegate = null;
}
if (Input.GetKeyDown (KeyCode.RightArrow))
{
velocity.x *= runSpeed;
anim.Play("Run Right");
                anim.animationCompleteDelegate = null;
}
if (Input.GetKeyDown (KeyCode.LeftArrow))
{
velocity.x *= runSpeed;
anim.Play("Run Left");
                anim.animationCompleteDelegate = null;
}
}
}

This one will move the character but the animation sticks on the first frame -

Code: [Select]
using UnityEngine;
using System.Collections;

public class AnimControllerTest : MonoBehaviour {

public float runSpeed;
public float gravity;
public int lookDirection = 1;
Vector2 velocity = Vector2.zero;

tk2dAnimatedSprite anim;

void Start ()
{
anim = GetComponent<tk2dAnimatedSprite>();
}

void Update ()
{

CharacterController player = GetComponent < CharacterController > ();

if (player.isGrounded)
{
velocity = new Vector2 (Input.GetAxis ("Horizontal"),0);
WalkAndRun();
WhereAmILooking();

}

velocity.y -= gravity * Time.deltaTime;
player.Move (velocity * Time.deltaTime);

}

void WalkAndRun ()
{
if (velocity.x == 0 && lookDirection == 1)
{
anim.Play("Idle Right");
                anim.animationCompleteDelegate = null;
}
if (velocity.x == 0 && lookDirection == 0)
{
anim.Play("Idle Left");
                anim.animationCompleteDelegate = null;
}
if (velocity.x > 0  && lookDirection == 1)
{
velocity *= runSpeed;
anim.Play("Run Right");
                anim.animationCompleteDelegate = null;
}
if (velocity.x < 0  && lookDirection == 0)
{
velocity *= runSpeed;
anim.Play("Run Left");
                anim.animationCompleteDelegate = null;
}
}

void WhereAmILooking ()
{

if (velocity.x > 0)
{
lookDirection = 1;
}
if (velocity.x < 0)
{
lookDirection = 0;
}
}
}

Im fairly new to all this and would appreciate any help in letting me know where im going wrong.

Thanks,

Ross.

Pages: [1]