BitmapMovieClip
In some cases in a project, we need to use striped sprites, it means an an animation of bitmaps which has their frames arranged in rows or columns like the examples below:
Sometimes the output of some graphic tools are this kind of sprite, for example this explosion generator: http://www.geocities.com/starlinesinc Actionscript do not brings anything built-in to handle this kind of sprites what I called Bitmap MovieClip, so I created a handy class to handle this situations where we need want to create an animation from an array of frames on an image.
The result is something like this:
The use of this class is very simple and is not too different from using a regular MovieClip, in fact the class IS a MovieClip, BitmapMovieClip inherits from the MovieClip class and can be treated like that.
public function TestMClip()
{
mBmpClip = new BitmapMovieClip( new explode(), 4,4);
this.addChild( mBmpClip );
mBmpClip.frameDelay = 40 ;
mBmpClip.loopTimes = 0 ;
mBmpClip.play();
mBmpClipB = new BitmapMovieClip( new orb(), 1,5);
mBmpClipB.y = 150 ;
this.addChild( mBmpClipB );
mBmpClipB.frameDelay = 100 ;
mBmpClipB.loopTimes = 0 ;
mBmpClipB.play();
}
The constructor receive three parameters. The first is the Bitmap with the frames of the animation, the second and third are rows and column respectively it means how many rows and columns the animation has, for example in our first example shown previously our explosion has four rows and four columns, while the second animations has only one row and five columns.
The frameDelay property is a measure of time in miliseconds, is the time what the frame will be shown before to switch to the next animation frame.
The loopTimes property is the number of times what the animation will be played, if this is zero the loop will be for ever.
The play method must be called to start running the animation. And thats it.
You can find the source of this sample and the BitmapMovieClip class here.
Tags: Actionscript, animations, as3, bitmap, BitmapMovieClip, flash, flex, movieclip, sprite, sprites
You can comment below, or link to this permanent URL from your own site.
