CAAT.Behavior

Out-of-the-box behaviors

Every actor is defined with a method chain call like the following:
                        var behavior= new CAAT.<Type>Behavior().
                            setValues( values parameters ).
                            setFrameTime( start_time, duration ).
                            setCycle( boolean, by default no ).
                            addListener( {
                                behaviorApplied : function(...),
                                behaviorExpired : function(...)
                            } );
                    

CAAT.AlphaBehavior

This behavior must have two values, one for the start alpha and another for the last alpha value. This alpha value affects to a container and its children honoring the isGlobalAlpha property. The method setValues accepts two values from zero to 1.

CAAT.RotateBehavior

The method setValues accepts four values: the two first values define the starting and ending rotation angle values in radians. The other two values are the rotation anchor point defined in relative percent to actor's width and height. The two values at 50 means rotation around actor's center. These two values must be between zero and a hundred.

If no anchor values are specified, actor's center will be set by default.

CAAT.ScaleBehavior

The method setValues accepts six values: the two first values define the starting and ending x axis scale values. The two next values define the starting and ending y axis scale values. The last two define an anchor point for scale just like CAAT.RotateBehavior does. Both anchors can be different so that you can set rotation around the center and scale from bottom right corner

If no anchor values are specified, actor's center will be set by default.

CAAT.PathBehavior

The method setValues accepts one single value which must be a CAAT.Path object instance. The actor origin (0,0) position and not its center will be positioned on the path.

This behavior has two exclusive methods:

The function setAutorotate(boolean) if set, actors traversing a path will be rotated accordingly so that it heads to the next path point.

The function setTranslation(x,y) define an offset displacement to set what actor position you want to be on the path instead its origin.. deprecated see Actor.setPositionAnchor(anchorx,anchory).

The following example show a rectangle centered and traversing a path:

            var director = new CAAT.Director().initialize(
                    250,250,document.getElementById('_c6'));
            var scene=  director.createScene();

            var shape= new CAAT.StarActor().
                    initialize( 8, 30, 10 ).
                    setLocation( 50,50 ).
                    setSize(50,50).
                    setFillStyle('#00f').
                    setStrokeStyle('#0f0').
                    setOutlined(true).
                    setAlpha(.75);

            // add two rectangle shapes to the scene.
            scene.addChild(shape);

            // create a circular path.
            var path= new CAAT.Path().
                    beginPath(25,125).
                    addCubicTo( 25,25,   225,25,   225,125 ).
                    addCubicTo( 225,225,  25,225,  25,125 ).
                    endPath();

            // add an actor to show the path.
            var path_actor= new CAAT.PathActor().
                    setPath(path).
                    setBounds(0,0,director.width,director.height);
            scene.addChild( path_actor );

            // setup up a path traverser for the path.
            var path_behavior= new CAAT.PathBehavior().
                    setPath( path ).
                // take 5 seconds to traverse the path
                    setFrameTime(0,5000).
                // do it continuously, not just one time
                    setCycle(true).
                // head the actor across the path to the next point.
                    setAutoRotate( true ).
                // set path traverse by the center of the rectangle shape.
                    setTranslation(
                        shape.width/2,
                        shape.height/2);

            shape.addBehavior( path_behavior );

            CAAT.loop(30);