I try to develop a simple flash game using a doublebuffer to draw the animations.
The redraw happens when Event.ENTER_FRAME is fired.
The backbuffer used for doublebuffering is of type BitmapData.
The animation is very simple: I draw a 20x20-pixel Bitmap into the backbuffer with increasing x coordinate, so that it should move smoothly from the left to the right side of my canvas. This basically works fine, but if you look closely, you will see significant disruptions in this movement. This does not seem to be related to the frame rate, since its constantly over 60. The disruptions of the smooth moving are not acceptable for an animations, but I'm quite sure I've done nothing wrong with the doublebuffering, so I'm scared this could be a flash-player problem or something... I would be very relieved if this were not the case
Please have a look at the swf showing the simple animation:
https://dl.dropbox.com/u/55967135/test.swf
(Btw. the disruptions of the animation also don't disappear when the movement is based on the time between two frames - by now its constant 2 pixels per frame.)
I've uploaded a very lightweight flash builder project including the whole sourcecode for the swf above: https://dl.dropbox.com/u/55967135/test.zip
public function enterFrame():void
{
// Calculate the time since the last frame (NOT USED IN THE EXAMPL PROGRAM)
var thisFrame : Date = new Date();
var dT : Number = (thisFrame.getTime() - lastFrame.getTime())/1000.0;
lastFrame = thisFrame;
// erase backBuffer
backBuffer.fillRect(backBuffer.rect, 0xFFFFFFFF);
// set new postion of the small testimage
if (this.pos > 600 || this.pos < 0) {
this.direction = !this.direction;
}
// increase / decrease vertical position
if (this.direction) {
this.pos += 2;
} else {
this.pos -= 2;
}
//trace(pos);
// draw small test image at postion "offset"
backBuffer.copyPixels( this.testGraphic.bitmap.bitmapData,
this.testGraphic.bitmap.bitmapData.rect,
new Point(pos, 0.0));
}
The enterFrame() is a method of my class GraphicsController, which handles the doublebuffering. It is launched by the applications enterFrame(event) method:
public function enterFrame(event:Event):void
{
GraphicsController.Instance.enterFrame();
myCanvas.graphics.clear();
myCanvas.graphics.beginBitmapFill(GraphicsController.Instance.backBuffer, null, false, false);
myCanvas.graphics.drawRect(0, 0, this.width, this.height);
myCanvas.graphics.endFill();
stage.invalidate();
}
Help would be GREATLY appreciated
Thank you