Hello Guest

Author Topic: caching 2d toolkit commands  (Read 3511 times)

meta87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
caching 2d toolkit commands
« on: January 27, 2013, 06:04:52 pm »
I've been using 2d Toolkit for a mobile game and so far everything is working great. Performance even better than I'd hoped.

One thing that I'm curious about is if it's beneficial to cache different commands in the start function instead of calling something like Play("animation") directly in update. I was reading on Unity's forum that calling strings frequently can be slow. I'm already doing this with thisTransform = this.transform for example.

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: caching 2d toolkit commands
« Reply #1 on: January 27, 2013, 07:59:49 pm »
You can cache animation names / sprite names -> ids if you'd like to save the lookup. Calling strings frequently isn't going to be as fast as that, but as with everything else it depends on what else you're doing at the time.
If you want to you can do this like so:
int animationId = animatedSprite.GetClipIdByName("...");
and call
animatedSprite.Play(animationId);
later.

In 1.90 final, you willalso be able to do something like this
tk2dSpriteAnimationClip clip = animatedSprite.GetClipByName("...");
and call play with this.
The advantage to this is that your clips could be from different animation libraries.

Once again though, this is only necessary if it is becoming a bottleneck..

meta87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: caching 2d toolkit commands
« Reply #2 on: January 28, 2013, 06:41:41 am »
Thanks a lot for the quick response and good info.