Actionscript:
-
[SWF(width=600,height=400,backgroundColor=0x000000,frameRate=30)]
-
var mcs:Vector.<MovieClip> = new Vector.<MovieClip>();
-
var num:int = 2000;
-
for (var i:int = 0; i<num; i++){
-
var s:MovieClip = new MovieClip();
-
s.graphics.lineStyle(0,0xFFFFFF);
-
s.graphics.drawCircle(0,0, Math.random()*30 + 3);
-
s.x = Math.random()*stage.stageWidth;
-
s.y = Math.random()*stage.stageHeight;
-
// comment out to kill your cpu
-
s.cacheAsBitmap = true;
-
addChild(s);
-
s.vx = Math.random() * 2 - 1;
-
s.vy = Math.random() * 2 - 1;
-
mcs.push(s);
-
}
-
addEventListener(Event.ENTER_FRAME, onCenter);
-
function onCenter(evt:Event):void{
-
for (var i:int = 0; i<num; i++){
-
mcs[i].x += mcs[i].vx;
-
mcs[i].y += mcs[i].vy;
-
}
-
}
This was created in response to a question about the real speed gain of cacheAsBitmap. Just comment out the cacheAsBitmap line to see the difference.
Despite it's extreme simplicity, this is actually a rather fun file to play with, change some of the graphics class method calls around and see what happens.
One Trackback
[...] Circles & cacheAsBitmap [...]