Posts Tagged ‘tweenlite’

Sunday, April 11th, 2010

iTween is a tweening kit for Unity that is in the same style as TweenLite, Tweener and others in the tween format that is common for flash tween libraries in Actionscript 3. This library is available in javascript and C# for Unity 3d Projects and is quite fast and solid.

iTween is a simple one file drop in for some great scripted animation and easing that is very reminiscent of Flash using Penner equations and common libraries so it is easy to get started. It works for web player, desktop and iPhone Unity (however long that lasts).

Some sample code looks like this:

private GameObject go;
private GameObject cam;

void Awake()
{
    go = gameObject;
    cam = Camera.main.gameObject;
}

private void Start()
{
    iTween.rotateFrom(go, 1.5f, 0, null, 90, null, iTween.EasingType.easeInExpo);
    iTween.moveFrom(go, 1.5f, 0, null, 3.5f, null, iTween.EasingType.easeInExpo);
    iTween.colorTo(go, .3f, 1.5f, 3, .5f, 1.2f);
    iTween.shake(cam, .8f, 1.5f, null, .3f, null);
    iTween.scaleTo(go, 2, 2.3f, null, 2, null);
    iTween.rotateBy(go, null, 4.3f, .5f, null, null);
    iTween.moveTo(go, null, 4.6f, null, 1.2f, null);
    iTween.moveTo(go, null, 5.8f, null, 0, null, iTween.EasingType.easeInExpo);
    iTween.shake(cam, .8f, 6.8f, null, .3f, null);
    iTween.colorTo(go, .5f, 7.6f, .165f, .498f, .729f);
    iTween.scaleTo(go, null, 7.6f, null, 1, null);
}
Thursday, February 5th, 2009

Recently two compact tweening engines have been released. Grant Skinner’s GTweeny and laborat’s ByteTween. This adds to the two that focus on micro-tween kit sizes in TweenLite and TweensyZero

Basically these engines look to be micro and provide pretty nice features while being so small. Micro tweening engines like GTweeny (3k), ByteTween (1.7k), TweenLite (2.7k), TweensyZero (2.9k) and Tweener (9k) have varying levels of support of features (Tweener being the most loaded with color and filter support without other kits just init, also TweenLite with a nice configurator to include only what you need).  Micro kits have benefits when used for banners, animated assets (where you have many assets and the per asset savings is worthwhile) and other places you just want really small output.

Light Transition ByteTween

(1.7k)

This kit has a c# version as well as a small as3 bytetween version.

The ByteTween static class eats only 1.7K of compiled clip! With this size it supports:

  • Creation of tweens of any numeric property (not color/uint properties).
  • Pause,Unpause,Cancel operations based on the tween target and property.
  • Overlap system that cancel tweens of same property in order to avoid erroneous behavior
  • Alpha tween with negative alpha support (negative alpha sets the MovieClip visibility to false)
  • ’scale’ tween of both ’scaleX’ and ’scaleY’ properties.
  • OnComplete callback with any number of parameters
  • Easy interface for creating new tweens!

Download light_transition_CS_0.5a.zip.zip (c# version)

Download thelab_ByteTween.zip

TweenLite

(2.7k) base

  • SPEED – I’m not aware of any popular tweening engine with a similar feature set that’s as fast as TweenLite. See the speed comparisons yourself.
  • Feature set – In addition to tweening ANY numeric property of ANY object, TweenLite can tween filters, hex colors, volume, tint, saturation, contrast, frames, and even do bezier tweening, plus LOTS more. TweenMax extends TweenLite and adds even more capabilities like pause/resume, rounding, event listeners, timeScale, and more. Overwrite management is an important consideration for a tweening engine as well which is another area where the GreenSock tweening platform shines. You have options for AUTO overwriting or you can manually define how each tween will handle overlapping tweens of the same object.
  • Expandability – With its new plugin architecture, you can activate as many (or as few) features as your project requires. Or write your own plugin if you need a feature that’s unavailable. Minimize bloat, and maximize performance.
  • Management featuresTweenGroup makes it surprisingly simple to create complex sequences and groups of TweenLite/Max tweens that you can pause(), resume(), restart(), or reverse(). You can even tween a TweenGroup’s “progress” property to fastforward or rewind the entire group/sequence.
  • Ease of use – Designers and Developers alike rave about how intuitive the GreenSock tweening platform is.
  • Updates – Frequent updates and feature additions make the GreenSock tweening platform reliable and robust.
  • AS2 and AS3 – Most other engines are only developed for AS2 or AS3 but not both.

Download TweenLite

TweensyZero

(2.9k) base

Here are some simple steps to help you get started with creating your first animations with TweensyZero. TweensyZero is a light weight version of Tweensy most core features found in Tweensy are available to TweensyZero. Documentation for TweensyZero can be found under the folder ‘documentation/zero’ or online

Download TweensyZero

gTweeny

(3k)

gTweeny is gTween‘s lightweight younger sibling. It strips a lot of the secondary features of GTween (proxy, timing modes, etc) in favour of smaller file size. It is currently under 3kb…

Download gTweeny

Here is a list of all open AS3 “Micro” Tweening engines < 5k

Here is a list of all open AS3 Tweening engines and base kits

The decision on which to use can be affected be features you want, how it feels (many use the same object syntax so it is dynamic), what performance do they have (all are orders of magnitude faster than the built in tween (flash) or transitions (mx/flex)), which size is ok, author/community support needed (some are more active than others adding features or simplifying and tweaking performance methodically), and many other factors.  There are definitely plenty to choose from.

Speed Tests for many Tween Engines

For more on each features see their sites or these previous lists on tweening engines:

Friday, January 16th, 2009

I use a SoundManager class for games and interactives that require it which I picked up at evolve by Matt Przybylski.  But I sometimes need to use Tweener rather than TweenLite depending on what the project uses already. So here is the class updated with Tweener.  Just grab the latest Tweener to work with this.  Sound is one of those things like tweening, it is easier to reuse code if everyone uses common libraries.

package game.util
{
	import caurina.transitions.properties.SoundShortcuts;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundLoaderContext;
	import flash.media.SoundTransform;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	import flash.utils.getQualifiedClassName;
	import caurina.transitions.*;
	/**
	 * The SoundManager is a singleton that allows you to have various ways to control sounds in your project.
	 *

	 * The SoundManager can load external or library sounds, pause/mute/stop/control volume for one or more sounds at a time,
	 * fade sounds up or down, and allows additional control to sounds not readily available through the default classes.
	 *

	 * This class is dependent on TweenLite (http://www.tweenlite.com) to aid in easily fading the volume of the sound.
	 *
	 * @author Matt Przybylski [http://www.reintroducing.com]
	 * @version 1.0
	 *
	 * @author Ryan Christensen (http://drawlogic.com)
	 * @version 1.1 - added Tweener support and removed TweenLite support
	 */
	public class SoundManager
	{
//- PRIVATE & PROTECTED VARIABLES -------------------------------------------------------------------------
		// singleton instance
		private static var _instance:SoundManager;
		private static var _allowInstance:Boolean;
		private var _soundsDict:Dictionary;
		private var _sounds:Array;
//- PUBLIC & INTERNAL VARIABLES ---------------------------------------------------------------------------
//- CONSTRUCTOR -------------------------------------------------------------------------------------------
		// singleton instance of SoundManager
		public static function getInstance():SoundManager
		{
			if (SoundManager._instance == null)
			{
				SoundManager._allowInstance = true;
				SoundManager._instance = new SoundManager();
				SoundManager._allowInstance = false;
			}
			return SoundManager._instance;
		}
		public function SoundManager()
		{
			this._soundsDict = new Dictionary(true);
			this._sounds = new Array();
			if (!SoundManager._allowInstance)
			{
				throw new Error("Error: Use SoundManager.getInstance() instead of the new keyword.");
			}
		}
//- PRIVATE & PROTECTED METHODS ---------------------------------------------------------------------------
//- PUBLIC & INTERNAL METHODS -----------------------------------------------------------------------------
		/**
		 * Adds a sound from the library to the sounds dictionary for playing in the future.
		 *
		 * @param $linkageID The class name of the library symbol that was exported for AS
		 * @param $name The string identifier of the sound to be used when calling other methods on the sound
		 *
		 * @return Boolean A boolean value representing if the sound was added successfully
		 */
		public function addLibrarySound($linkageID:*, $name:String):Boolean
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				if (this._sounds[i].name == $name) return false;
			}
			var sndObj:Object = new Object();
			var snd:Sound = new $linkageID;
			sndObj.name = $name;
			sndObj.sound = snd;
			sndObj.channel = new SoundChannel();
			sndObj.position = 0;
			sndObj.paused = true;
			sndObj.volume = 1;
			sndObj.startTime = 0;
			sndObj.loops = 0;
			sndObj.pausedByAll = false;
			this._soundsDict[$name] = sndObj;
			this._sounds.push(sndObj);
			return true;
		}
		/**
		 * Adds an external sound to the sounds dictionary for playing in the future.
		 *
		 * @param $path A string representing the path where the sound is on the server
		 * @param $name The string identifier of the sound to be used when calling other methods on the sound
		 * @param $buffer The number, in milliseconds, to buffer the sound before you can play it (default: 1000)
		 * @param $checkPolicyFile A boolean that determines whether Flash Player should try to download a cross-domain policy file from the loaded sound's server before beginning to load the sound (default: false)
		 *
		 * @return Boolean A boolean value representing if the sound was added successfully
		 */
		public function addExternalSound($path:String, $name:String, $buffer:Number = 1000, $checkPolicyFile:Boolean = false):Boolean
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				if (this._sounds[i].name == $name) return false;
			}
			var sndObj:Object = new Object();
			var snd:Sound = new Sound(new URLRequest($path), new SoundLoaderContext($buffer, $checkPolicyFile));
			sndObj.name = $name;
			sndObj.sound = snd;
			sndObj.channel = new SoundChannel();
			sndObj.position = 0;
			sndObj.paused = true;
			sndObj.volume = 1;
			sndObj.startTime = 0;
			sndObj.loops = 0;
			sndObj.pausedByAll = false;
			this._soundsDict[$name] = sndObj;
			this._sounds.push(sndObj);
			return true;
		}


		/**
		 * Removes a sound from the sound dictionary.  After calling this, the sound will not be available until it is re-added.
		 *
		 * @param $name The string identifier of the sound to remove
		 *
		 * @return void
		 */
		public function removeSound($name:String):void
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				if (this._sounds[i].name == $name)
				{
					this._sounds[i] = null;
					this._sounds.splice(i, 1);
				}
			}
			delete this._soundsDict[$name];
		}
		/**
		 * Removes all sounds from the sound dictionary.
		 *
		 * @return void
		 */
		public function removeAllSounds():void
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				this._sounds[i] = null;
			}
			this._sounds = new Array();
			this._soundsDict = new Dictionary(true);
		}
		/**
		 * Plays or resumes a sound from the sound dictionary with the specified name.
		 *
		 * @param $name The string identifier of the sound to play
		 * @param $volume A number from 0 to 1 representing the volume at which to play the sound (default: 1)
		 * @param $startTime A number (in milliseconds) representing the time to start playing the sound at (default: 0)
		 * @param $loops An integer representing the number of times to loop the sound (default: 0)
		 *
		 * @return void
		 */
		public function playSound($name:String, $volume:Number = 1, $startTime:Number = 0, $loops:int = 0):void
		{
			var snd:Object = this._soundsDict[$name];
			snd.volume = $volume;
			snd.startTime = $startTime;
			snd.loops = $loops;
			if (snd.paused)
			{
				snd.channel = snd.sound.play(snd.position, snd.loops, new SoundTransform(snd.volume));
			}
			else
			{
				snd.channel = snd.sound.play($startTime, snd.loops, new SoundTransform(snd.volume));
			}
			snd.paused = false;
		}
		/**
		 * Stops the specified sound.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return void
		 */
		public function stopSound($name:String):void
		{
			var snd:Object = this._soundsDict[$name];
			snd.paused = true;
			snd.channel.stop();
			snd.position = snd.channel.position;
		}
		/**
		 * Pauses the specified sound.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return void
		 */
		public function pauseSound($name:String):void
		{
			var snd:Object = this._soundsDict[$name];
			snd.paused = true;
			snd.position = snd.channel.position;
			snd.channel.stop();
		}
		/**
		 * Plays all the sounds that are in the sound dictionary.
		 *
		 * @param $useCurrentlyPlayingOnly A boolean that only plays the sounds which were currently playing before a pauseAllSounds() or stopAllSounds() call (default: false)
		 *
		 * @return void
		 */
		public function playAllSounds($useCurrentlyPlayingOnly:Boolean = false):void
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				var id:String = this._sounds[i].name;
				if ($useCurrentlyPlayingOnly)
				{
					if (this._soundsDict[id].pausedByAll)
					{
						this._soundsDict[id].pausedByAll = false;
						this.playSound(id);
					}
				}
				else
				{
					this.playSound(id);
				}
			}
		}
		/**
		 * Stops all the sounds that are in the sound dictionary.
		 *
		 * @param $useCurrentlyPlayingOnly A boolean that only stops the sounds which are currently playing (default: true)
		 *
		 * @return void
		 */
		public function stopAllSounds($useCurrentlyPlayingOnly:Boolean = true):void
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				var id:String = this._sounds[i].name;
				if ($useCurrentlyPlayingOnly)
				{
					if (!this._soundsDict[id].paused)
					{
						this._soundsDict[id].pausedByAll = true;
						this.stopSound(id);
					}
				}
				else
				{
					this.stopSound(id);
				}
			}
		}
		/**
		 * Pauses all the sounds that are in the sound dictionary.
		 *
		 * @param $useCurrentlyPlayingOnly A boolean that only pauses the sounds which are currently playing (default: true)
		 *
		 * @return void
		 */
		public function pauseAllSounds($useCurrentlyPlayingOnly:Boolean = true):void
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				var id:String = this._sounds[i].name;
				if ($useCurrentlyPlayingOnly)
				{
					if (!this._soundsDict[id].paused)
					{
						this._soundsDict[id].pausedByAll = true;
						this.pauseSound(id);
					}
				}
				else
				{
					this.pauseSound(id);
				}
			}
		}
		/**
		 * Fades the sound to the specified volume over the specified amount of time.
		 *
		 * @param $name The string identifier of the sound
		 * @param $targVolume The target volume to fade to, between 0 and 1 (default: 0)
		 * @param $fadeLength The time to fade over, in seconds (default: 1)
		 *
		 * @return void
		 */
		public function fadeSound($name:String, $targVolume:Number = 0, $fadeLength:Number = 1):void
		{
			var fadeChannel:SoundChannel = this._soundsDict[$name].channel;
			SoundShortcuts.init();
			Tweener.addTween(fadeChannel, { _sound_volume: $targVolume, time: $fadeLength, transition:"linear" } );
			//TweenLite.to(fadeChannel, $fadeLength, {volume: $targVolume});
		}
		/**
		 * Mutes the volume for all sounds in the sound dictionary.
		 *
		 * @return void
		 */
		public function muteAllSounds():void
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				var id:String = this._sounds[i].name;
				this.setSoundVolume(id, 0);
			}
		}
		/**
		 * Resets the volume to their original setting for all sounds in the sound dictionary.
		 *
		 * @return void
		 */
		public function unmuteAllSounds():void
		{
			for (var i:int = 0; i < this._sounds.length; i++)
			{
				var id:String = this._sounds[i].name;
				var snd:Object = this._soundsDict[id];
				var curTransform:SoundTransform = snd.channel.soundTransform;
				curTransform.volume = snd.volume;
				snd.channel.soundTransform = curTransform;
			}
		}
		/**
		 * Sets the volume of the specified sound.
		 *
		 * @param $name The string identifier of the sound
		 * @param $volume The volume, between 0 and 1, to set the sound to
		 *
		 * @return void
		 */
		public function setSoundVolume($name:String, $volume:Number):void
		{
			var snd:Object = this._soundsDict[$name];
			var curTransform:SoundTransform = snd.channel.soundTransform;
			curTransform.volume = $volume;
			snd.channel.soundTransform = curTransform;
		}
		/**
		 * Gets the volume of the specified sound.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return Number The current volume of the sound
		 */
		public function getSoundVolume($name:String):Number
		{
			return this._soundsDict[$name].channel.soundTransform.volume;
		}
		/**
		 * Gets the position of the specified sound.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return Number The current position of the sound, in milliseconds
		 */
		public function getSoundPosition($name:String):Number
		{
			return this._soundsDict[$name].channel.position;
		}
		/**
		 * Gets the duration of the specified sound.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return Number The length of the sound, in milliseconds
		 */
		public function getSoundDuration($name:String):Number
		{
			return this._soundsDict[$name].sound.length;
		}
		/**
		 * Gets the sound object of the specified sound.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return Sound The sound object
		 */
		public function getSoundObject($name:String):Sound
		{
			return this._soundsDict[$name].sound;
		}
		/**
		 * Identifies if the sound is paused or not.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return Boolean The boolean value of paused or not paused
		 */
		public function isSoundPaused($name:String):Boolean
		{
			return this._soundsDict[$name].paused;
		}
		/**
		 * Identifies if the sound was paused or stopped by calling the stopAllSounds() or pauseAllSounds() methods.
		 *
		 * @param $name The string identifier of the sound
		 *
		 * @return Number The boolean value of pausedByAll or not pausedByAll
		 */
		public function isSoundPausedByAll($name:String):Boolean
		{
			return this._soundsDict[$name].pausedByAll;
		}
//- EVENT HANDLERS ----------------------------------------------------------------------------------------
//- GETTERS & SETTERS -------------------------------------------------------------------------------------
		public function get sounds():Array
		{
			return this._sounds;
		}
//- HELPERS -----------------------------------------------------------------------------------------------
		public function toString():String
		{
			return getQualifiedClassName(this);
		}
//- END CLASS ---------------------------------------------------------------------------------------------
	}
}