2D Toolkit Forum
2D Toolkit => Support => Topic started by: TinSleeves on January 06, 2013, 12:34:27 am
-
I'm just trying to make a sprite fade out and I read that using HOTween is recommended, but I can't seem to get it to work on a tk2d sprite. Does anyone have an example bit of code for something like that?
I've looked at this thread http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,542.msg2555.html#msg2555 and for some reason I still can't seem to get my head round it!
Thanks
-
Here's the simplest use of HOTween for fading out the sprite:
tk2dSprite spr;
float time = 1.0f;
HOTween.To(spr, time, new TweenParms().Prop("color", new Color(1.0f, 1.0f, 1.0f, 0.0f)));
In the other thread's example there should be two methods named UpdateTextMesh and FadeOutCompleteLevelRendered. You should know a bit about .NET delegates and casting in order to implement UpdateTextMesh. If that confuses you, here's how you can make use of .NET anonymous methods:
tk2dSprite spr;
float time = 1.0f;
HOTween.To(
spr,
time,
new TweenParms()
.Prop("color", new Color(1.0f, 1.0f, 1.0f, 0.0f))
.OnStart(
() =>
{
// insert code to execute on start of tweening (this is optional)
})
.OnUpdate(
() =>
{
// insert code to execute on each update (this is optional)
})
.OnComplete(
() =>
{
// insert code to execute when tweening completes (this is optional)
}));
If you want to fade out a tk2dTextMesh instance, you will have to call Commit inside OnUpdate.
If you want to fade out multiple sprites/textmeshes/... (or tween any other property) at the same time with single call to HOTween.To you can also use OnUpdate. Here's an example for fading out two textmeshes and a sprite at the same time:
HOTween.To(
txt1,
time,
new TweenParms()
.Prop("color", new Color(1.0f, 1.0f, 1.0f, 0.0f))
.OnUpdate(
() =>
{
txt1.Commit();
txt2.color = txt1.color;
txt2.Commit();
spr.color = txt1.color;
}));
-
This is perfect thanks for the help!
Yeah I don't have a clue about .NET but using and modifying these examples I was able to get exactly what I wanted