Archive for the ‘Animation’ Category

TweenLite, Tweener, GOASAP | Fun with animation packages

Friday, January 18th, 2008

I have been speaking a lot about Tweener these days and for a good reason; it’s a really good as3 animation library. I can’t say I have been having trouble with it but I found evidence from different sources that it might not be the best animation package for what I want to do.

What I am doing is mostly websites and in those website I use ActionScript to make everything move; I rarely use the timeline. All of my tweens are at most 1 second long but most of the time they last about 0.5 second. I liked Tweener because it was way better than Adobe’s Tween classes but I found from 2 different sources (TweenLite, GOASAP) that TweenLite is faster for small tweens than Tweener. You might know that already, but being fast is one of the most important attribute for me in a tweening engine. Not so much because I use too much animation at the same time but more because that when I start Tweens, I don’t want them to eat all of the cpu, I want them too leave as much processing power for other stuff like timeline animations, video etc. These is all to say that I am changing all my code from Tweener to Tweenlite (that I had previously changed from Adobe Tween classes to Tweener) because I need the extra speed badly.

Something came up since I started this project. From the maker of the Fuse kit comes GOASAP. Which looks very promissing; it’s  not an animation package per say, it’s more like animation package building blocks. Since sometime there is a lot of overhead in animation engine for things that you will never use, Moses Supposes made us all animation library developers. The GOASAP code base is in AS3 and I can’t wait to start using it. In the mean time I invite you all to go and start developing your own animation code;

Tweener and tweening colors

Thursday, November 29th, 2007

I did a previous post about the static method Color.interpolateColor, but at that time, I hadn't really tried Tweener yet. Let me tell you this, tweening colors has never been easier than with Tweener. I'm am going to redo the same example showing you how simple it is to use Tweener instead of Color.interpolateColor form the fl.motion.Color package. Here is the code, you just have to paste it on a frame an compile it to swf to make it work (you have to have the Tweener classes in your folder or in one of the default class folder).

Actionscript:
  1. import caurina.transitions.*;
  2.  
  3. var simpleSprite:Sprite = new Sprite();
  4. simpleSprite.x = 100;
  5. simpleSprite.y = 100;
  6. simpleSprite.graphics.lineStyle();
  7. simpleSprite.graphics.beginFill(0xff0000);
  8. simpleSprite.graphics.drawRect(0,0,200,100);
  9. addChild(simpleSprite);
  10. simpleSprite.buttonMode = true;
  11.  
  12. simpleSprite.addEventListener(MouseEvent.MOUSE_OVER, makeBlue);
  13. simpleSprite.addEventListener(MouseEvent.MOUSE_OUT, makeRed);
  14.  
  15. function makeBlue(e:MouseEvent):void{
  16. Tweener.addTween(simpleSprite, {_color:0x0000ff, time:1, transition:"easeOutQuart"});
  17. }
  18. function makeRed(e:MouseEvent):void{
  19. Tweener.addTween(simpleSprite, {_color:null, time:1, transition:"easeOutQuart"});
  20. }

That's it. And it does exactly the same thing and probably faster than the Tween classes. Notice that it takes only one line of code to change the color instead of the more complex method I used previously . Also you only have to import the Tweener classes as opposed to six import statements.

Well that's it for today, I'll try and investigate on more Tweener properties because it just keep surprising me.

Making a simple button using Tweener and Sprites in AS3

Saturday, November 24th, 2007

In a previous tutorial, I showed how to make a simple button using the Tween classes and Sprites. I am going to redo the same tutorial but using Tweener instead. I am not going to re-explain the first step which are all the same than in the previous tutorial; I am just going to speak about the mouse handler functions.

So here is the new code using Tweener:

Actionscript:
  1. package{
  2. import flash.display.Sprite;
  3. import flash.text.TextField;
  4. import flash.events.MouseEvent;
  5. import caurina.transitions.*;
  6. public class simpleButton extends Sprite{
  7. public function simpleButton(newLabel:String){
  8. myLabel.text = newLabel;
  9. myLabelOver.text = newLabel;
  10. myLabelOver.alpha = 0;
  11. buttonMode = true;
  12. mouseChildren = false;
  13. addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver);
  14. addEventListener(MouseEvent.MOUSE_OUT, handleMouseOut);
  15. addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
  16. }
  17. private function handleMouseOver(event:MouseEvent):void{
  18. Tweener.addTween(this.Over,{alpha:1, time:0.5, transition:"linear"});
  19. Tweener.addTween(this.myLabelOver,{alpha:1, time:0.5, transition:"linear"});
  20. Tweener.addTween(this.myLabel,{alpha:0, time:0.5, transition:"linear"});
  21. }
  22. private function handleMouseOut(event:MouseEvent):void{
  23. Tweener.addTween(this.Over,{alpha:0, time:0.5, transition:"linear"});
  24. Tweener.addTween(this.myLabelOver,{alpha:0, time:0.5, transition:"linear"});
  25. Tweener.addTween(this.myLabel,{alpha:1, time:0.5, transition:"linear"});
  26. }
  27. private function handleMouseUp(event:MouseEvent):void{
  28. }
  29. }
  30. }

The major advantage of Tweener in the case of a rollover and a rollout (like most buttons) is that you don't have to keep track of previous Tweens in order to stop them. With the Tween classes, if you don't do that, you're going to end up with strange rollover behaviors.  Also, we had to check if the Tween  existed before trying to stop them which added extra code. Tweener handles all that for us which is pretty practical. I spoke some times of the Fuse Kit; it seems packed with a lot of options, but you can't do simple rollovers with it; with Tweener you can.

Well I'm about done with my tutorial on Tweener but I think I'll do one about using Tweener to Tween between two colors, just like Color.interpolateColor static method.

ActionScript 3 Tweener Basic Tutorial

Friday, November 23rd, 2007

On my previous tutorial about how to do Tweens  using ActionScript 3 I used the Tween classes from Adobe. At the time I didn't know about Tweener and the Fuse Kit didn't have a version in ActionScript 3. I have used Tweener a bit now and I can say that I am starting to like it a lot.

For this tutorial I am going to do exactly what I did in the previous tutorial but this time I'll use Tweener. The first thing you have to do, as with the Tween classes, is import Tweener, you do it in this way.

Actionscript:
  1. import caurina.transitions.*

Tweener as some easing classes in it but you can also use the easing classes from Flash. One good side of Tweener is that it compile perfectly fine in Flex. Tween and easing classes don't compile with Flex... A down side of Tweener is that it adds an additional 8k to your file (as opposed to 2k for Tween classes for a total of 10k).  Ok so now we are ready to go.

Actionscript:
  1. Tweener.addTween(rectangle, {x:300, time:3, transition:"linear"});

The "Tweener.addTween" part is how you add a Tween, that's kinda obvious. "rectangle" is the name of the object you want to do a Tween on one of its property (or more). "x:300" is the final x position that rectangle will be at. "time:3" is the time it will take to get there and "transition:'linear'" is the easing to use. You see this is already easier to use and to read than the Tween classes. One major change is that you input the starting position of the property. I think this is a good thing since like 90% of the time I have been doing Tween, I want the Tween to start from the current position of the property and you can just set the property before doing the Tween anyway.

The next example was about doing multiple Tweens on the same object but on different properties here is how we did it with the Tween classes:

Actionscript:
  1. <pre>var myTweenX:Tween = new Tween(rectangle, "x", Strong.easeOut, 0, 300, 3, true);
  2. var myTweenAlpha:Tween = new Tween(rectangle, "alpha", Strong.easeOut, 0, 1, 3, true);
  3. var myTweenAlpha:Tween = new Tween(rectangle, "width", Strong.easeOut, rectangle.width, rectangle.width + 300, 3, true);
  4. var myTweenAlpha:Tween = new Tween(rectangle, "rotation", Strong.easeOut, 0, 90, 3, true);</pre>

Here is how you would do that with Tweener:

Actionscript:
  1. Tweener.addTween(rectangle, {x:300,alpha:1, width:rectangle.width + 300, rotation:90, time:3, transition:"linear"});

So in one line I did what it used to take me 4 and it easy pretty easy to understand.

Another thing that is really nice with Tweener is that it as a delay property. If you want your Tween to start in 1 second you do it in this way:

Actionscript:
  1. Tweener.addTween(rectangle, {alpha:1, time:3, delay:1, transition:"linear"});

This is practical when you want to do Tweens in sequence (one after the other). With the Tween classes you would do it in this way:

Actionscript:
  1. <pre>var myTweenX:Tween = new Tween(bloc, "alpha", Strong.easeOut, 0, 1, 3, true);
  2. myTweenX.addEventListener(TweenEvent.MOTION_FINISH, doNextTween);</pre>
  3. <pre>
  4. function doNextTween(e:TweenEvent):void{
  5. var myTweenAlpha:Tween = new Tween(bloc, "x", None.easeOut, 0, 300, 3, true);
  6. myTweenX.removeEventListener(TweenEvent.MOTION_FINISH, doNextTween);
  7. }</pre>

With Tweener:

Actionscript:
  1. Tweener.addTween(bloc, {alpha:1, time:3, transition:"linear"});
  2.  
  3. Tweener.addTween(bloc, {x:300, time:3, delay:3, transition:"linear"});

As you can see you use way less code using Tweener and it tends to keep all your code for an animation together which will be easier to understand when you come back. Also I have seen some benchmark and Tweener seems to be performing better than the Tween classes. So all in all I guess I am just going to ditch the Tween classes and start using Tweener from now on.

Using fl.* packages in Flex and more

Tuesday, November 13th, 2007

Slow days at work means I get to experiment and search the web for new ways to develop. I did a lot of research today on Flex until I stumbled on this presentation on the beedigital blog. It's a very nice presentation on how to integrate Flash and Flex in your workflow. That's exactly what I wanted. After see it I tried to do some test projects in Flex. Most of the time I do every thing in ActionScript so I thought this wouldn't be too difficult. The trouble is that most of the time I also use the Tween and Easing classes from Flash. These classes come in the fl.* package and this package does not compile in Flex. I searched a bit how I could make these classes compile but I only found complicated methods of doing so. I tired also to use the Tween classes from Flex, but in order to use them you have also to include the Flex framework which adds 100k to your project. My simple solution to this problem; using Tweener for my tweens. Tweener only adds 10k to a swf file compared to the fuse engine (which is not in AS3 yet). It's not so bad, it's only a 8k difference to the Flash Tween classes (2k). Also using it a bit, I might have misjudged Tweener a bit because it works very well. I might in the future redo some example using Tweener instead of the Tween classes.

I went on the blog of Samuel Asher Rivell, the author of the presentation I spoke of earlier, and found some other interesting things. First there is the Montreal Game Summit that's going to be held on November 27th and 28th. I live in Montreal so I'd be pretty happy to go there, at least on the first day. It has some interesting conferences about Flash that I'd like to see especially the one given by Samuel Asher Rivell on Advertgames.  The second nice thing I found on his blog is the powerpoint presentation of one of the conference he gave on blitting. I had seen the technique some time on the web but never knowing what it was or how to do it. His presentation is a good introduction to it and I'd be really interested in hearing his speach about it. There might be more on blitting on this blog since it looks really promising.

My new friend setTint

Thursday, October 25th, 2007

I played around today with a method named setTint from the fl.motion.Color class. At first I was a bit confused because this method doesn't return anything contrarily to the interpolateColor method which returns a color in hexadecimal. You have to use setTint in this way:

Actionscript:
  1. import fl.motion.Color;
  2. import flash.geom.ColorTransform;
  3. var ct:Color = new Color();
  4. ct.setTint(0xFF0000, 0.5);
  5. mc.transform.colorTransform = ct;

With mc being the displayObject you want it applied on. setTint can be pretty useful for setting a tint on a bitmap and it can also be used with tweens in the same way I used the interpolateColor in a previous post.

Tweening colors using Color.interpolateColor

Sunday, October 21st, 2007

I have been looking for a long time for a way to tween colors in Flash and while browsing around I came across the Color class and the interpolateColor method. I then wanted to see how it worked. It is not that obvious so here is the code:

Actionscript:
  1. import fl.transitions.Tween;
  2. import fl.transitions.TweenEvent;
  3. import fl.transitions.easing.*;
  4. import fl.motion.Color;
  5. import flash.events.*;
  6. import flash.geom.ColorTransform;
  7.  
  8. var simpleSprite:Sprite = new Sprite();
  9. simpleSprite.x = 100;
  10. simpleSprite.y = 100;
  11. simpleSprite.graphics.lineStyle();
  12. simpleSprite.graphics.beginFill(0xff0000);
  13. simpleSprite.graphics.drawRect(0,0,200,100);
  14. addChild(simpleSprite);
  15.  
  16. // Get access to the ColorTransform instance associated with our sprite.
  17. var colorInfo:ColorTransform = simpleSprite.transform.colorTransform;
  18. // This function is called when the stage is clicked.
  19. function makeBlue(event:MouseEvent):void
  20. {
  21.   var tempMovie:Sprite = new Sprite();
  22.   var alphaOver:Tween = new Tween(tempMovie, "alpha", Strong.easeOut,0, 1, 8, true);
  23.   alphaOver.addEventListener(TweenEvent.MOTION_CHANGE, tweenToBlue);
  24. }
  25. function tweenToBlue(event:TweenEvent):void{
  26.   // apply the change to the display object
  27.   colorInfo.color = Color.interpolateColor(0xff0000, 0x003399, event.position);
  28.   simpleSprite.transform.colorTransform = colorInfo;
  29. }
  30. stage.addEventListener(MouseEvent.CLICK, makeBlue);

The first block of code is to import all that is needed to do our Tweening. The two classes that are of importance are the fl.motion.Color and flash.geom.ColorTransform.

In the second block of code, I create the Sprite that I will do the tweening on and draw a red rectangle in it using the graphics.drawRect method.

After that, it's the listening function to the mouse event CLICK on the stage. This function create a new Sprite that will never be displayed. Its sole purpose will be to use its properties to do our Tween. Then we create our Tween as we would normally and we add a listener for the MOTION_CHANGE event.

All the good stuff happens in the next function; tweenToBlue. It is here that we use the static method interpolateColor of the Color class. We use the event's position to give us the place where theTween is at. That is why in our Tween as to have the start parameter as to be 0 and the end parameter as to be 1. We than apply to colorTransform to our Sprite.

2 new tutorials and SEO

Tuesday, October 9th, 2007

I have been busy this weekend, I have made two new tutorials about how to time your animations, one in ActionScript 2, one in ActionScript 3. I hope this help.

If you noticed there is the word SEO (search engine optimization) in the title of the blog but I didn't have the time to write about it yet. In the meanwhile I can direct you to the website the-flash-files made by Nurun , a web agency in Montreal (actually a competitor of the company I work for).

Tweener and stuff

Friday, October 5th, 2007

Today I found another tweening engine called Tweener. For those who knows it, it is the successor of MC Tween. It looks great, it permits you to do tweens on a lot of properties and there is a delay argument, so your code will look cleaner (without all the setTimeout). The down side is still the weight, well it's way less than the Fuse kit but still; 9.2kb for ActionScript 2 or 10.4 kb for ActionScript 3. This include all of the Robert Penner's original easing equations and there is a nice page showing the difference between each of them. I think I will try this code some time soon and I'll give you feedback about it.

This weekend, I'll try to work on the wordpress template because I think it looks too common and it's way too narrow, ActionScript code doesn't look like I would like it to. Maybe I'll have time to update the ActionScript 3 Tween tutorial too.

Using the Fuse kit for animation versus using the Tween Classes

Tuesday, September 18th, 2007

Most of what I will write about is interesting stuff I found while searching for something. When searching for the tween classes in Flash CS3 I stumble two times on people speaking about the fuse kit for animation. I have as a motto to check out things that I hear about twice, so that the next time it comes up, I know what people are talking about. In this case this could even be helpful for my job, so I go and check it out.

The fuse kit are some ActionScript2 classes that simplify that syntax of doing animation using ActionScript. It has 3 parts; one is the Zigo Engine which handles the tweening. It can be used as a standalone. The second part is Fuse itself, which are sequencing classes that helps you organize your tween in time. The last part is FMP which permits you to use filters with Fuse.

This all looks pretty good, with it you can do tweens in sequence as well as in parallel. I say to myself, that is fantastic, I will be able to get rid of the setTimeout in my code and my ActionScript will be simpler to understand.

There is only one catch; The Zigo engine in itself adds to your SWF 34k, Fuse: 2k and FMP: 1k for a grand total of 37k. So it rules out the possibility to use it in banners and such. When I make a flash movie, I want it to be as small as possible so the idea of starting my SWFs at 37k doesn't make me happy. Also you can't use the Fuse kit to do roll overs; I do all my rollovers in actionscript so I would have to import the tween classes from Adobe too to add another 2k. For me it just doesn't cut it; if my website as more than one SWF it's 39k I have to add each time.

So in the end, the Fuse kit looked pretty good, but its advantages don't match up with its disadvantages...


Close
E-mail It