There are times in games and experimental apps that you really need speed… there are a bunch of ways to speed up the rendering of your swf… the most effective technique I’ve found is to totally do away with sprites and movieClips - although this isn’t always possible, there are plenty of times when it is… Instead use BitmapData and copyPixels to draw… The following code snippet pasted in your flash timeline will draw 10,000 transparent circles that follow the mouse:
stage.frameRate = 31;
var imageNum:int = 10000;
var point:Point = new Point(0,0);
var s:Sprite = new Sprite();
s.graphics.beginFill(0xCCCCCC);
s.graphics.lineStyle(0,0x000000);
s.graphics.drawCircle(3,3,3);
s.alpha = .2;
var nested:Sprite = new Sprite();
nested.addChild(s);
var image:BitmapData = new BitmapData(s.width, s.height, true, 0x00000000);
image.draw(nested);
var canvas:BitmapData = new BitmapData(400,400, true, 0xFFFFFFFF);
var frame:Bitmap = new Bitmap(canvas);
addChild(frame);
var xPos:Array = new Array();
var yPos:Array = new Array();
for (var i:int = 0; i<imageNum; i++){
xPos.push(Math.random()*400);
yPos.push(Math.random()*400);
}
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
canvas.fillRect(new Rectangle(0,0,400,400), 0xFFFFFFFF);
var div:Number;
for (var i:int = 0; i<imageNum; i++){
div = (i / 100)+2;
xPos* += (mouseX - xPos*)/div;
yPos* += (mouseY - yPos*)/div;
point.x = xPos*;
point.y = yPos*;
canvas.copyPixels(image, image.rect, point, null, null, true)
}
}
A few things to note about this… using copyPixels() instead of draw() is important… the draw() method of BitmapData seems to be pretty slow. So if you don’t need complex transformations like scale, skew, rotation etc… your good to go. If you do need these things you can pre-calculate them as a series of bitmaps and then play through them… There are a few libraries out there that do that… like this one: http://www.bytearray.org/?p=117