Go 0.4.8jg1 + HydroTween rev30 + Guide + Source Code
The latest rev is 32. I have added the changes to this document in addition to the other updates.
Update 31d Fixed a bug from the removal of OverlapMonitor. Thanks John!
Update 32 Smoothness issue has been fixed with pulseInterval and example updated for 0.4.9. Start Values have been added for non-color/image matrix properties
Update 33 Made a couple updates and a post for the FlashBelt 2008 conference. A few more examples. I also added a DisplayObject3D target argument in the init3D() method for running a lookAt() during scene renders. Click here for the recent post.
HydroTween.go(mc, {color:0xFF0000}, 2, 0, Elastic.easeOut);
// Fuse style sequencing!
var seq1:SequenceCA = HydroTween.parseSequence(
{target:fusebox, x:320, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, Blur_blurX:8, Blur_blurY:8, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, color:0×0000FF, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, Blur_blurX:0, Blur_blurY:0, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, x:400, seconds:.5, easing:Quadratic.easeInOut},
{target:fusebox, rotation:270, seconds:.5, easing:Quadratic.easeInOut}
);
seq1.start();
After a short hiatus from the blog, and a wedding, I’ve been able to knock out some much needed changes and additions to HydroTween. I’m excited about this because now I can move onto the fun stuff and I’ve started putting together a roadmap of sorts. Go has been picking up steam and examples have been popping up which is great to see. Most people seem to think there are two types of users of Go. The ones that simply want to tween away, have something functioning, and useful right away. The other types are interested in developing their own tweening system and animation utilities either for all around use or for specialized applications. I’m excited about the 3rd group which falls in the middle. These are the people that want the first, but find themselves becoming the latter just because of the Methodology of Go. I used to be in the first group for quite some time until Go came along and then I found myself thrown intro the world of tweening. I’ve been saying this for some time now, but the beauty of Go is that you might find yourself in the middle with very little effort. Once you it that point, consider yourself an addict. This post should help with a general understanding of HydroTween. I also hope this post will open some eyes to the idea of going it along and giving their own parser a shot. That said I will start with the usage of HydroTween and it’s updates, then I will follow with my own trial and tribulations of reaching this recent version. The example below along with the source is located at the end of this post.
Click here for the Go Project Site - Go Project Site
Click here for the Go Playground Project Site - Home of Parsers/User Generated Go projects and examples.
Current Tweenable Properties:
- alpha
- Bevel_angle
- Bevel_blurX
- Bevel_blurY
- Bevel_color
- Bevel_distance
- Bevel_highlightAlpha
- Bevel_highlightColor
- Bevel_quality
- Bevel_shadowAlpha
- Bevel_shadowColor
- Bevel_strength
- Blur_blurX
- Blur_blurY
- Blur_quality
- brightness
- color
- contrast
- DropShadow_alpha
- DropShadow_angle
- DropShadow_blurX
- DropShadow_blurY
- DropShadow_color
- DropShadow_distance
- DropShadow_quality
- DropShadow_strength
- Glow_alpha
- Glow_blurX
- Glow_blurY
- Glow_color
- Glow_quality
- Glow_strength
- height
- hue
- pan
- rotation
- rotationX (PV3D)
- rotationY (PV3D)
- rotationZ (PV3D)
- saturation
- scaleX
- scaleY
- scaleZ (PV3D)
- text
- tint
- volume
- width
- x
- y
- z (PV3D)
What’s new in this version:
- Image/Bitmap/ColorMatrix property refactoring such as contrast, brightness, etc. Color tweening has been added as well. Worked out some bugs and streamlined.
- Fuse style sequencing.
- An autostart parameter.
- Updated reverse and cycle structure.
- Started porting over the previous textfield tweening functionality.
- Tweening of multiple targets as Arrays
- Papervision3D tweening functions
- start_ values for non image/color matrix tweening. (This will be addded soon!)
Autostart:
Autostart has been deprecated from version 30. In version 31, go calls() and sequence() methods start automatically. To setup a sequence that doesn’t start, use the parseSequence() method.
LinearGoRepeater:
The static go() method and the constructor have been updated to reflect the changes in version 0.4.8. An object has been added that provides parameters for cycling back and forth. You can either input a LinearGoRepeater instance, or you can use a generic object.
Fuse style Sequence Tweening:
var seq1:SequenceCA = HydroTween.sequence(
{target:fusebox, x:320, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, Blur_blurX:8, Blur_blurY:8, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, color:0×0000FF, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, Blur_blurX:0, Blur_blurY:0, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, x:400, seconds:.5, easing:Quadratic.easeInOut},
{target:fusebox, rotation:270, seconds:.5, easing:Quadratic.easeInOut}
);
// This sequence will NOT start automatically. Allows you to create sequences and store them
var seq2:SequenceCA = HydroTween.parseSequence(
{target:fusebox, x:320, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, Blur_blurX:8, Blur_blurY:8, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, color:0×0000FF, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, Blur_blurX:0, Blur_blurY:0, seconds:5, easing:Quadratic.easeInOut},
{target:fusebox, x:400, seconds:.5, easing:Quadratic.easeInOut},
{target:fusebox, rotation:270, seconds:.5, easing:Quadratic.easeInOut}
);
seq2.start();
Tweening Examples:
F.Y.I. The flash interface/example above will copy the code to the clipboard.
General:
Filter:
Image/Bitmap/ColorMatrix:
HydroTween.go(mc, {brightness:2}, 2, 0, Elastic.easeOut);
// Contrast
HydroTween.go(mc, {contrast:2}, 2, 0, Elastic.easeOut);
// Hue
HydroTween.go(mc, {hue:45}, 2, 0, Elastic.easeOut);
// Saturation
HydroTween.go(mc, {saturation:-1}, 2, 0, Elastic.easeOut);
// Tint
HydroTween.go(mc, {tint:0×00FF00}, 2, 0, Elastic.easeOut);
// Color
HydroTween.go(mc, {color:0xFF0000}, 2, 0, Elastic.easeOut);
// Color Reset (This will tween back to it’s original value
HydroTween.go(mc, {color:-1}, 2, 0, Elastic.easeOut);
Matrix tweening (for array values such as sepia, etc) should make a return in the next update as well as a tint percentage value.
Sound:
HydroTween.go(soundchannel, {volume:.1}, 2, 0, Elastic.easeOut);
// Contrast
HydroTween.go(soundchannel, {pan:-1}, 2, 0, Elastic.easeOut);
Sound tweening takes the SoundChannel instance as a target.
Text:
This simply tweens the number from 0 to whatever param is specified and outputs to a textfield. I hope to expand on the functionality of this soon.
Using Callbacks and Updaters:
HydroTween.go(textfield, {text:100}, 2, 0, Elastic.easeOut, onCompleteHandler);
// Update Callback
HydroTween.go(textfield, {text:100}, 2, 0, Elastic.easeOut, null, onUpdateHandler);
Papervision3D Tweening:
I have added a convenient function for setting up your renderer for HydroTween. This is called once before you call any tweens and runs the renderer during any tween.
HydroTween.init3D(renderer, scene, camera, viewport);
// Simple Papervision3D Tween
HydroTween.go(plane, {rotationX:100, z:500}, 2, 0, Elastic.easeOut);
Also be sure to check out John Grden’s kickass Go3D parser.
Roadmap and upcoming updates:
- Text tweening to support prefix and suffix String values
- Even more modular format for adding tweenable properties
- Drawning and spline/bezier tweening/Catmull Rom/etc
- Continuing with speed enhancements
The Making of HydroTween
For those of you interested in setting up your own tweening parser, hopefully this section will offer some insight. Getting these updates was a bit of a challenge and I learned quite a bit. Because of this, I think my ultimate vision for HydroTween has changed a bit. With the flexibility Go offers, the task of how to manage tweens and properties falls in the hands of the Go practitioner. The efficiency of a tweening engine really boils down to the simplicity of it’s core and the reading and routing of updating property values. How this is achieved can explain the large number of different tweening systems out there. My hope is to eventually set up HydroTween to extend the open foundation of the Go system to it’s tweenable properties making them more modular and easy to tweek. Let’s forget about how the Go core engine works for a minute and look at the bare bones processes invloved in tweening.
- First we need some way to parse a syntax of our choosing.
- We need to keep track of where/what the end result of our tween will be.
- We need to figure out the starting value of the tween.
- We need to figure out the difference of the starting and ending value.
- We need to update the values of that difference over a period of time.
- We need to route the updated values to the tweens target based on the type of property that’s being tweened.
This is a very general idea of what’s going on here. Now some of the above has been taken out of the equation and/or made easier to accomplish. The parsing is being left up to us, along with how we store and route the updating property values. We have a place to figure out the starting point as well as where to update the data. The trick is how to do it.
I’ve found that most tweenable properties fall into a few categories:
Some are direct properties of an object, such as the x value of a Sprite.
sprite.x = 1;
// "Tweenable" syntax:
sprite[“x”] = 1;
Some are done through object’s filters, such as BlurFilter and DropShadow.
var gf:GlowFilter = new GlowFilter();
gf.color = 0xFF0000;
box.filters = [gf];
// "Tweenable" syntax:
box.filters = [new GlowFilter()];
var f:Array = box.filters;
f[0][“color”] = 0×0000FF;
box.filters = f;
Some are done through a transform property, or a combination of transform properties, such as volume or some color changing.
var tf:* = targ.soundTransform;
tf.volume = val;
targ.soundTransform = tf;
// "Tweenable" syntax:
var tf:* = targ[“soundTransform”];
tf[“volume”] = val;
targ[“soundTransform”] = tf;
The above examples are straight forward, but they point out the process of parsing. We are using a String reference to the Objects property which allows us to match it up in our property list. This is where we define our syntax and essentially becomes our “key”. Every key in our parser must be unique so we can match up a respective property. In the case of blurX, we have to specify that it is either the BlurFilter, GlowFilter, etc. So Blur_blurX is added to a key/property list which matches that property with the functions needed to update the BlurFilter and target in the Objects filter Array.
Some use a combination of Filter and Matrix math such as contrast, color, hue. Some use value pairs, such as drawing. The rest I have found use either a single or double value, along with some constants such as spline animation, text, etc. You can refer to the source for the more complicated examples as they require a couple extra steps. Just to give you the general idea. With ColorMatrix we are tweening an entire array of values. What HydroTween does is depending on the property settings, an “adjustment” function is called. This changes the end values for the array, and the write function updates the entire array from point A to B. Since an Object can have multiple ColorMatrix adjustments made to it, we need to call these first before running the tween. Thanks again to Grant Skinner for letting me import and tweek his ColorMatrix class.
All of these items are easy to tween in their own right, but when you combine them all together, that’s when things get tricky. I’ve organized my functions in a read, write, and for some an adjust and path category. “Read” simply gets the objects existing state, “write” updates the objects property value, “adjust” modifies a property prior to writing it (such as ColorMatrix transformations of a ColorMatrix Array before tweening it), and “path” is a param that accesses an objects property.
My goal now is to continue to make this more efficient and modular in a way that the average user can create a read function, a write function, and register it to the property list along with any additional params it might need. It’s sorta there, but there is much work to be done:)
I’m still no tweening Jedi and this is an ongoing work in progress. Any suggestions, complaints, and contributions are welcome.
Also I will be at Flashbelt. Hit me up if you are interested in meeting up. Looking forward to Moses’ presentation!
HydroTween rev32 Source and Example
May 14th, 2008 at 9:44 am
Donovan, this is really awesome work! Serious kudos.
May 14th, 2008 at 1:24 pm
You are the MAN. Thank you!
May 14th, 2008 at 1:26 pm
Hell yeah! GO just got new dimension. And it’s syntax friendly too.
Great work Donovan!
May 14th, 2008 at 1:35 pm
Thanks guys! Let me know how it goes, and let me know if you have any ideas:)
May 14th, 2008 at 3:29 pm
I’ve just got the mail from Moses. Thank you, thank you.
May 15th, 2008 at 1:27 am
Post has been updated with rev31 updates.
May 15th, 2008 at 9:42 am
The one thing holding me back from diving into AS3 has been the lack of a Fuse equivalent. Looks like you’ve provided it! Thanks, and now I look forward to long nights at my Mac learning new stuff.
May 15th, 2008 at 11:37 am
Great work/
May 15th, 2008 at 1:01 pm
I’ve also been holding off on AS3 for a nice fuse equivalent. This looks pretty sweet.
May 18th, 2008 at 12:53 pm
Thanks very much for this !
P.s. Which music am i hearing when testing the volume tween?
May 18th, 2008 at 2:06 pm
Abiogenesis” by Carbon Based Lifeforms on the World of Sleepers album. Great CD!
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?id=203743554&s=143441
June 2nd, 2008 at 7:44 am
Hey great work!
Just one question - how would you send parameters through to a tween complete handler? eg. if you were tweening multiple mc’s and wanted to know which mc had just called the handler?
I’m probably being dim.
June 2nd, 2008 at 9:56 am
I have yet to add params for arguments.. but the easiest way to do this for passing args to any function call is using a nested closure.
It’s a sneaky trick that works for all sorts of stuff:)
June 2nd, 2008 at 8:10 pm
Updated the source with the rev32 0.4.9 Code!
June 8th, 2008 at 8:20 am
[...] hydrotik | flash development / design / photographyflash development and creative playground of Donovan Adams Go 0.4.8jg1 + HydroTween rev30 + Guide + Source Code [...]
June 14th, 2008 at 10:42 am
Great, great work. From my perspective, this is the most robust — and yet simplest — animation class out there. Congratulations.
Don’t know if this helps anyway, but I’ve figured out a way to add listeners to a simple tween:
function single (e:MouseEvent):void {
var tween:IPlayable = HydroTween.go(fusebox, {x:400}, 2, 0, Elastic.easeOut);
tween.addEventListener(GoEvent.COMPLETE, test);
}
function test(e:GoEvent):void {
trace(”finished”);
}
Obviously, in this case you can achieve the same functionality using a callback, but I love the greater flexibility of listeners.
June 14th, 2008 at 1:47 pm
Thanks man!
You can do it this way, but this is the same as using:
The function argument is applied to the tween in the same way as you are adding the listener. It’s just happening internally. But this good for people to know as there is a definite need for breaking stuff out if you want to use the pause() resume() and other higher level functions of Go.
But thanks for pointing that out! I will include it in the documentation that I need to get together.
June 27th, 2008 at 1:07 pm
Greetings,
I am using this sequence but it not seems to have 180 seconds. What i am missing?
var seq1:SequenceCA = HydroTween.sequence(
{target:tapa6, x:443, seconds:180, easing:Quadratic.easeInOut},
{target:tapa6, x:443, seconds:180, easing:Quadratic.easeInOut},
{target:tapa6, alpha:0, seconds:180, easing:Quadratic.easeInOut},
{target:tapa6, x:-400, seconds:180, easing:Quadratic.easeInOut},
{target:tapa6, x:-400, seconds:180, easing:Quadratic.easeInOut},
{target:tapa6, alpha:1, seconds:180, easing:Quadratic.easeInOut},
{target:tapa6, x:443, seconds:180, easing:Quadratic.easeInOut}
);
June 27th, 2008 at 1:20 pm
Both work, but seconds seems to round to an int. I need to update the info on this page, but you should use duration int he meantime.
I also suggest you download the latest version if you are using rev30.
June 29th, 2008 at 8:35 pm
Nice work! I was able to add my favorite property “fade” into the class in no time and actually created a quick and dirty shortcuts class just like the fuse shortcuts.
July 18th, 2008 at 10:18 am
HydroTween, best tween engine ever. Thx for the big work. However it it would be handy, if this works without sequence or callback:
HydroTween.go(sprite, {x:100}, 1, 0, Cubic.easeInOut);
HydroTween.go(sprite, {x:0}, 1, 1, Cubic.easeInOut);
July 20th, 2008 at 10:35 am
Check out the latest for HydroSequence where you can easily do this. HydroTween doesn’t let you run a Tween on the same object at once. What you are looking to do is Sequencing, so check it out!