2D Toolkit Forum

2D Toolkit => Support => Topic started by: camelot10 on July 24, 2012, 05:24:39 pm

Title: Tint & Loop Sprite
Post by: camelot10 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.
Title: Re: Tint & Loop Sprite
Post by: 39thstreet 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.
Title: Re: Tint & Loop Sprite
Post by: nikolic 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.
Title: Re: Tint & Loop Sprite
Post by: unikronsoftware 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.
Title: Re: Tint & Loop Sprite
Post by: camelot10 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.
Title: Re: Tint & Loop Sprite
Post by: fsadeq 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.
Title: Re: Tint & Loop Sprite
Post by: camelot10 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?
Title: Re: Tint & Loop Sprite
Post by: camelot10 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;
}


}