我嘗試開發一個簡單的Flash遊戲,使用doublebuffer繪製動畫。使用doublebufferd畫布的簡單動畫不光滑
重繪時Event.ENTER_FRAME觸發發生。
用於doublebuffering的後備緩衝區是類型的BitmapData的。
動畫是很簡單的:我畫一個20×20像素的位圖與增加X後備緩衝座標,所以它應該從左邊到我的畫布的右側平滑地移動。這基本上可以正常工作,但如果仔細觀察,您會看到這一運動的重大幹擾。這似乎與幀速率沒有關係,因爲它一直超過60幀。順暢移動的中斷對於動畫是不可接受的,但我確信我沒有在雙緩衝中做任何錯誤,嚇得這可能是一個Flash播放器問題或東西...我會很放心,如果不是這種情況
請看看瑞士法郎顯示簡單的動畫:
https://dl.dropbox.com/u/55967135/test.swf
(順便說一句動畫的中斷也不當運動是基於兩個幀之間的時間消失 - 現在每幀其恆定2個像素)
我已經上傳了一個非常輕量級的Flash Builder項目包括整個源代碼上面的SWF: 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));
}
的enterFrame事件()是我的課GraphicsController,它處理doublebuffering的方法。
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();
}
幫助將不勝感激
謝謝