Tag Archives: Memphis

Actionscript 3 Animated Bitmap Part I

I’ve been working on games for awhile now, and I was looking for a way to make the process of taking art assets and bringing them into flash a little easier.  So my quest started where every quest should start now a days the interwebs!!

What I found was just what I was looking for, a web site called hexagonalstar.com had the info I needed to start creating my own Animated Bitmap class.  So I downloaded there source code and started to work.

I must say that without this source code I would have been stuck, it was very helpful and I just wanted to thank them for all their hard work.

Anyway lets get on to what my plans are.  First, I am slowly created a Flash API code name Memphis, which is a library to help me improve the development time of flash games.  So the animated bitmap class will be added to Memphis as another feature.

What I have right now is pretty simple, just the barebones of the class started.  I can take a bitmap from the library and create the animated bitmap from that image.  What I am planning is to have the ability to start and stop the animated bitmap on command and some other coolio stuff.

Below is my function to create the simple animated bitmap:

[code lang=”actionscript”]
var ab1:Sprite = MemphisAPI.AnimateBitmap({ image:ring_seq, width:32, height:32, columns:21,framerate:30});
[/code]

Which is then passed to Memphis which handles the process:

[code lang=”actionscript”]
public static function AnimateBitmap(Properties:Object):Sprite {
var sprite:Sprite = new Sprite();
var column:Number = 0;
var xPos:Number = 0;
var yPos:Number = 0;
var origData:BitmapData = BitmapData(new Properties.image(0,0));
var newData:BitmapData = new BitmapData(Properties.width,Properties.height,true,0x000000);
var animatedBitmap:Bitmap = new Bitmap(newData);

var timer:Timer = new Timer(Properties.framerate);
timer.addEventListener(TimerEvent.TIMER, timerFunc);
timer.start();

function timerFunc(e:TimerEvent) {
var _point:Point = new Point(0, 0);
var _rect:Rectangle = new Rectangle(xPos, yPos, 32, 32);
newData.copyPixels(origData, _rect, _point);
xPos += Properties.width;
sprite.addChild(animatedBitmap);
if(column > Properties.columns) {
xPos = 0;
column = 0;
}
column++;
}
return sprite
}
[/code]

So as you can see this is a very basic function right now, but hopefully if everything goes well I will have a fully working animated bitmap class.

Once again I want to thank the website hexagonalstar for pointing me in the right direction 🙂