Other CAAT actors

CAAT.ImageActor

This actor objects' functionalities are already available at any CAAT.Actor which is the preferred way of setting up actors with images.

The methods setOffsetX( offset ), setOffsetY( offset ), setOffset( offset_x, offset_y ) behave exactly as their counterparts on CAAT.Actor object instances.

The method setImage( image ) has its counterpart in CAAT.Actor method setBackgroundImage( image_or_spriteImage ).

This actor has a fine grained image drawing method via the call to setImageTransformation( transformation ). The transformation parameter must have any of the following values:

  • TR_NONE, no image transformation.
  • TR_FLIP_HORIZONTAL, set horizontal flip.
  • TR_FLIP_VERTICAL, set vertical flip.
  • TR_FLIP_ALL, set both horizontal and vertical flip.
  • TR_FIXED_TO_SIZE, scale image to fit actor's size.

Example

This example show 20 image actors continuously traversing a random cubic bezier path.

                            var director= new CAAT.Director().initialize(
                                    700,
                                    350,
                                    document.getElementById('_c6') );

                            var scene= director.createScene();

                            // define a resource preloader.
                            new CAAT.ImagePreloader().loadImages(
                                [ {id:'fish',     url:'resource/logo.png'} ],   // get only this image.
                                function( counter, images ) {

                                    if ( counter==images.length ) {             // when it is done loading

                                        // save loaded resources on Director.
                                        director.setImagesCache(images);

                                        for(var i=0; i<20; i++ ) {
                                            var fish =
                                                new CAAT.ImageActor().
                                                    setImage(director.getImage('fish')).
                                                    setImageTransformation(CAAT.ImageActor.prototype.TR_FIXED_TO_SIZE).
                                                    addBehavior(
                                                        new CAAT.PathBehavior().
                                                            setAutoRotate(true).
                                                            setPath( new CAAT.Path().setLinear(0,0,0,0) ).
                                                            setInterpolator(
                                                                new CAAT.Interpolator().createExponentialInOutInterpolator(2,false) ).
                                                            setFrameTime( scene.time, 10 ).
                                                            addListener( {
                                                                behaviorExpired : function(behaviour,time) {
                                                                    var endCoord= behaviour.path.endCurvePosition();
                                                                    behaviour.setPath(
                                                                            new CAAT.Path().setCubic(
                                                                                endCoord.x,
                                                                                endCoord.y,
                                                                                Math.random()*director.width,
                                                                                Math.random()*director.height,
                                                                                Math.random()*director.width,
                                                                                Math.random()*director.height,
                                                                                Math.random()*director.width,
                                                                                Math.random()*director.height) );
                                                                    behaviour.setFrameTime( scene.time, 3000+Math.random()*3000 )
                                                                }
                                                            })
                                                    );
                                            scene.addChild(fish);
                                        }

                                    }
                                });

                            CAAT.loop(60);

                        })();