Skip to content

@mimshwright /BitmapDrawComparison.as
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
On stage using bitmap caching
package {
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
[SWF(width="500", height="500", frameRate="50")]
public class BitmapDrawComparison extends Sprite {
public var timeDisplay:TextField;
public var lastTime:int = 0;
public function BitmapDrawComparison() {
addEventListener(Event.ENTER_FRAME, calculateTime);
var circle:Circle;
var i:int = 0;
for (; i < 400; i+=1) {
circle = new Circle();
circle.x = 500 * Math.random();
circle.y = 500 * Math.random();
circle.cacheAsBitmap = true;
addChild(circle);
}
timeDisplay = new TextField();
addChild (timeDisplay);
}
public function calculateTime(event:Event):void {
var now:int = getTimer();
timeDisplay.text = int(1000/(now - lastTime)) + "fps"; // runs around 20-24 fps and kinda chunky
lastTime = now;
}
}
}
import flash.display.*;
import flash.events.*;
import flash.geom.*;
/** Colored circle useded in demo. */
internal class Circle extends Sprite {
public var v:Point;
public function Circle() {
super();
graphics.beginFill([0xFF00FF,0xFFFF00,0x00FFFF][int(Math.random() * 3)], 1);
graphics.drawCircle(0, 0, 20);
blendMode = BlendMode.MULTIPLY;
scaleX = scaleY = .2 + (2 * Math.random());
v = new Point(Math.random() * 2 - 1, Math.random() * 2 - 1);
addEventListener(Event.ENTER_FRAME, update);
}
private function update(event:Event):void {
x += v.x;
y += v.y;
if (x < 0 || x > 500) { v.x = v.x * -1; }
if (y < 0 || y > 500) { v.y = v.y * -1; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.