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: 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 ;;

         mBmpClipB = new BitmapMovieClip( new orb(), 1,5);
         mBmpClipB.y = 150 ;
         this.addChild( mBmpClipB );
         mBmpClipB.frameDelay = 100 ;
         mBmpClipB.loopTimes = 0 ;;

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.

Explore posts in the same categories: Actionscript, flash

Tags: , , , , , , , , ,

You can comment below, or link to this permanent URL from your own site.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: