Hello Guest

Author Topic: Question about tk2dAnimatedSprite.SetFrame()  (Read 5165 times)

StrikerF2

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Question about tk2dAnimatedSprite.SetFrame()
« on: July 08, 2012, 04:21:33 pm »
Hi there, this has got me a little stumped, and I'd just like to know what I was doing wrong.

I'm attempting to set the frame of a sprite animation (Big surprise, I know :P), but try as I might, I can't seem to get the actual sprite in-game to change it's frame.

Here's what I've written:
Code: [Select]
void Start ()
{
// get the sprite component
sprite = GetComponent<tk2dAnimatedSprite>();
sprite.SetFrame(50);
}

It just never seems to update, and I can't fathom why.

I should also mention this is being placed as a component on a button. Should that cause any issue? Oh, and I'd also note that actually changing the animation clip seems to work fine, and it is set to not play as default.


Am I missing something really obvious? :P

StrikerF2

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Question about tk2dAnimatedSprite.SetFrame()
« Reply #1 on: July 08, 2012, 04:41:55 pm »
Nevermind, I sorted it. If only I had waited a few minutes :P

For anyone else that encounters this, looks like the sprite has to be set to play automatically in order for it to work.

If it's not too much trouble, would anyone be able to explain why this is the case? :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Question about tk2dAnimatedSprite.SetFrame()
« Reply #2 on: July 08, 2012, 05:41:20 pm »
It used to work like that for backwards compatibility, but in 1.76, this isn't necessary any more. I've changed it so it will work even if the animation isn't playing. It'll be in the next release.

If you need a fix now, replace the start of this function in tk2dAnimatedSprite.cs

Code: [Select]
public void SetFrame(int currFrame)
{
if (currentClip == null && anim != null)
{
currentClip = anim.clips[clipId];
}