Hello Guest

Author Topic: Tint & Loop Sprite  (Read 13638 times)

camelot10

  • Newbie
  • *
  • Posts: 24
    • View Profile
Tint & Loop Sprite
« on: July 24, 2012, 05:24:39 pm »
Im using default unity Animation and change tk 2d sprite Color.r, Color.g, Color.b values over time (with keyframes).
Also i set Animations as "loop".
When i start "play" - sprite color doesnt change. but inspector show color animation for tk 2d sprite.
what im doin wrong?


p.s. im realy new to unity and 2d toolkit. former flash/actionscript coder.

39thstreet

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 77
    • View Profile
Re: Tint & Loop Sprite
« Reply #1 on: July 24, 2012, 05:45:14 pm »

Not sure about your specific issue, but if you're coming from Flash and ever used TweenMax or TweenLite, check out HOTween: http://www.holoville.com/hotween/

Well optimized for performance and I've had good luck using it to tween all sorts of things in 2dtoolkit.

nikolic

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Tint & Loop Sprite
« Reply #2 on: July 24, 2012, 06:25:30 pm »
Try to change "color" property of sprite instance instead of changing "r", "g", "b" and "a" values individually.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tint & Loop Sprite
« Reply #3 on: July 24, 2012, 11:31:25 pm »
@camelot10.

The Unity animation system won't correctly animate tk2dSprite colors / spriteswitches. The reason for it is that Unity Animation system only animates member variables and not .net properties. I have a few different snippets of code I use when I need to do this. A bit more explanation on your needs and I could probably suggest what to do here.

As 39thstreet says, HOTween is excellent and works perfectly. If you're more comfortable with something like that then that will just work out of the box.

camelot10

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Tint & Loop Sprite
« Reply #4 on: July 25, 2012, 12:53:43 pm »
HOTween works very well. thanks alots for that tip.

update: just tested "export to flash". Hotween doesnt work, throw errors. log attached. also made issue here http://code.google.com/p/hotween/issues/detail?id=35


@camelot10.

The Unity animation system won't correctly animate tk2dSprite colors / spriteswitches. The reason for it is that Unity Animation system only animates member variables and not .net properties. I have a few different snippets of code I use when I need to do this. A bit more explanation on your needs and I could probably suggest what to do here.

As 39thstreet says, HOTween is excellent and works perfectly. If you're more comfortable with something like that then that will just work out of the box.

i just want to animated tint of sprite from white to red color, infinite, yoyo like.
« Last Edit: July 25, 2012, 01:39:19 pm by camelot10 »

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: Tint & Loop Sprite
« Reply #5 on: July 25, 2012, 02:20:12 pm »
I know a lot of people like HOTween, but you should also check out GoKit by Prime31 http://forum.unity3d.com/threads/133823-Prime31-GoKit-Tween-Library-Live
I was using HOTween, but recently switched over to this and I have to say the performance on mobile devices is superior.

camelot10

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Tint & Loop Sprite
« Reply #6 on: July 25, 2012, 04:40:03 pm »
I know a lot of people like HOTween, but you should also check out GoKit by Prime31 http://forum.unity3d.com/threads/133823-Prime31-GoKit-Tween-Library-Live
I was using HOTween, but recently switched over to this and I have to say the performance on mobile devices is superior.

GoKit support flash export?

camelot10

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Tint & Loop Sprite
« Reply #7 on: July 27, 2012, 11:13:59 am »
made this script.
itween (flash compatible).
with settings.

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

public class TintLoop : MonoBehaviour
{

public Color Color;
public float Duration;

void Start ()
{
tk2dSprite sprite = GetComponent<tk2dSprite>();
Hashtable options = new Hashtable();
options.Add("from", sprite.color);
options.Add("to", Color);
options.Add("time", Duration);
options.Add("OnUpdate", "updateSpriteColor");
options.Add("looptype", iTween.LoopType.pingPong);
options.Add("easetype", iTween.EaseType.linear);
iTween.ValueTo(gameObject, options);
}

void updateSpriteColor(Color color)
{
tk2dSprite sprite = GetComponent<tk2dSprite>();
sprite.color = color;
}


}