randomcrab / UnglidePCL

A tweening library for C#, implemented as a Portable Class Library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unglide

Unglide is a super-simple tweening library for C#.

This is a Git and PCL/NuGet fork--not port--of Jacob Albano's Glide. You can find the original here. Some things may have changed and may be undocumented.

Installation

Unglide is available on NuGet. To install, run the following command in the Package Manager Console:

PM> Install-Package EdCanHack.Unglide

Use

Create a Tweener instance and use it to manage tweens:

var Tweener = new Tweener();
Tweener.Tween(...);

Every frame, update the tweener.

Tweener.Update(ElapsedSeconds);

Tweening

Tweening properties is done with a call to Tween. Pass the object to tween, an anonymous type instance containing value names and target values, and a duration, with an optional delay.

//	This tween will move the X and Y properties of the target
Tweener.Tween(target, new { X = toX, Y = toY }, duration, delay);

You can also use Glide to set up timed callbacks. Unlike Glide, these callbacks return a value between 0.0 and 1.0 representing the completion status of the tween.

Tweener.Timer(duration, delay).OnComplete(CompleteCallback);

Control

If you need to control tweens after they are launched (for example, pausing or cancelling), you can hold a reference to the object returned By Tween():

var myTween = Tweener.Tween(object, new {X = toX, Y = toY}, duration);

You can later use this object to control the tween:

myTween.Cancel();
myTween.CancelAndComplete();

myTween.Pause();
myTween.PauseToggle();

myTween.Resume();

Calling a control method on a tweener will affect all tweens it manages.

If you'd rather not keep tween controller objects around, you can also control them by passing an object being tweened to a target control function.

Tweener.Tween(myObject, ...);

Tweener.TargetCancel(myObject);
Tweener.TargetCancelAndComplete(myObject);

Tweener.TargetPause(myObject);
Tweener.TargetPauseToggle(myObject);

Tweener.TargetResume(myObject);

Behavior

You can specify a number of special behaviors for a tween to use. Calls can be chained for setting more than one at a time.

//  Glide comes with a full complement of easing functions
Tweener.Tween(...).Ease(Ease.ElasticOut);

Tweener.Tween(...).OnComplete(() => Console.WriteLine("done"));
Tweener.Tween(...).OnUpdate((completion) => Console.WriteLine("updating, at {0}%", Convert.ToInt32(completion * 100)));

//  Repeat twice
Tweener.Tween(...).Repeat(2);

//  Repeat forever
Tweener.Tween(...).Repeat();

//  Reverse the tween every other time it repeats
Tweener.Tween(...).Repeat().Reflect();

//  Swaps the end and start values of a tween.
//  This is helpful if you want to set an object's properties to one set of values, and then tween back to the previous values.
Tweener.Tween(...).Reverse();

//  Smoothly interpolate a rotation value past the end of an axis.
Tweener.Tween(...).Rotation();

//  Round tweened properties to integer values
Tweener.Tween(...).Round();

About

A tweening library for C#, implemented as a Portable Class Library.

License:MIT License


Languages

Language:C# 100.0%