I have a problem with drawing bitmapData in AS3 with an onEnterFrame action. It worked great in AS2, and now that I converted it to AS3, it's bogging down on my system rather slowly.... I'm using the dispose() method on both bitmapData instances I have, and I can only notice the slowness after about 10 minutes of playing it...
Hope somone has an insight about the issue. Here is a snippet of my code:
Code:
function enterFrameEvent(e:Event) {
makeKlydo();
}
function makeKlydo(){
stampImage = new BitmapData(this.myElement["k"+myElementObject].width, this.myElement["k"+myElementObject].height, true, 0xFFFFFF);
stampImage.draw(myElement, new Matrix(1, 0, 0, 1, this.myElement["k"+myElementObject].width/2, this.myElement["k"+myElementObject].height));
if (deceleration<1){
deceleration -= (deceleration-1)/5;
}
if (rotate1) {
r += rotspeed1 * fanning * deceleration;
}
if (rotate2) {
r2r -= rotspeed2 * fanning * deceleration;
}
if (rotate3) {
rot += rotspeed3 * fanning;
}
map.dispose();
map = new BitmapData(hsize, vsize, true, 0x00000000);
mapBM = new Bitmap(map);
mapHolder.addChild(mapBM);
for (var i = 0; i<slices; i++) {
m.identity();
m.b += sh1;
m.c += sh2;
m.rotate(r2r);
m.translate(myElement.width/2,myElement.height);
m.rotate(r);
m.scale(scl, scl);
slice.graphics.clear();
slice.graphics.lineStyle();
slice.graphics.moveTo(0, 0);
slice.graphics.beginBitmapFill(stampImage, m);
slice.graphics.lineTo(Math.cos((angle+nudge)-Math.PI/2)*diag, Math.sin((angle+nudge)-Math.PI/2)*diag);
slice.graphics.lineTo(Math.cos(-(angle+nudge)-Math.PI/2)*diag, Math.sin(-(angle+nudge)-Math.PI/2)*diag);
slice.graphics.lineTo(0, 0);
slice.graphics.endFill();
m.identity();
if (flip && i%2 == 1) {
m.scale(-1, 1);
}
//m.rotate(rot+i*angle*2*fanning);
m.rotate(rot+i*angle*2);
m.translate(hsize*0.5, vsize*0.5);
map.draw(slice, m, null, "normal", null, true);
}
stampImage.dispose();
}
addEventListener(Event.ENTER_FRAME, enterFrameEvent);
thank!
First of all it looks like you are adding a new Bitmap object to mapHolder on every frame, but you aren't removing any of them as far as I can tell, so mapHolder is just going to end up with a zillion Bitmap objects attached to it. Instead of creating a new Bitmap object each time you could just use the Bitmap.bitmapData property to change the BitmapData the Bitmap is displaying.
You are also creating new BitmapData objects on each frame but you aren't using any of the BitmapData methods that would improve rendering times. BitmapData.draw() uses the vector renderer, so unless I have missed something the use of BitmapData objects seems a bit excessive for what you are doing there.