2012-06-08 120 views
1

我正在試圖將動畫片段繪製到位圖數據,並使其看起來像是我剛剛將動畫片段直接添加到舞臺上一樣。然而結果轉移。我懷疑它與起源和界限有關,但無法弄清楚。將動畫片段繪製爲位圖數據左右移動

http://megaswf.com/s/2441986 (右邊的一個問題)

package 
{ 
    import flash.display.Sprite; 
    import flash.events.Event; 
    import flash.display.MovieClip; 
    import flash.display.Bitmap; 
    import flash.display.BitmapData; 
    import flash.geom.Matrix; 
    import flash.geom.Rectangle; 

    public class Main extends Sprite 
    { 
     public var movieClip:MovieClip; 
     public var bitmapData:BitmapData 
     public var bitmap:Bitmap; 

     public function Main():void 
     { 
      if (stage) init(); 
      else addEventListener(Event.ADDED_TO_STAGE, init); 
     } 

     private function init(e:Event = null):void 
     { 
      removeEventListener(Event.ADDED_TO_STAGE, init); 
      addEventListener(Event.ENTER_FRAME, update); 


      // for comparison, this is what I want the result to look like 
      movieClip = new skeletonWalk(); 
      movieClip.x = 200; 
      movieClip.y = 200; 
      addChild(movieClip); 

      // and this it the problem child 
      bitmap = new Bitmap(); 
      bitmap.x = 300; 
      bitmap.y = 200; 
      addChild(bitmap); 
     } 

     private function update(e:Event):void 
     { 
      var bounds:Rectangle = movieClip.getBounds(movieClip); 
      bitmapData = new BitmapData(bounds.width, bounds.height, true, 0x0); 
      bitmapData.draw(movieClip, new Matrix(1, 0, 0, 1, -bounds.x, -bounds.y)); 
      bitmap.bitmapData = bitmapData; 
     } 

    } 

} 

回答

2

你畫你的影片剪輯中的位圖的左上角,作爲剪輯改變其高度時,劍處於直立位置整個事情都下降了。

嘗試固定底部邊緣,而不是頂部邊緣。

bitmapData.draw(movieClip, new Matrix(1, 0, 0, 1, -bounds.x, maxMCheight - (bounds.y + bounds.height))); 
//maxMCheight is the height of the clip while the sword is risen 
+0

謝謝,我得到它使用你的方法工作。我還必須將位圖數據大小增加到maxMCHeight,因爲它現在在底部被切斷了一點。 – WgFunstorm

+0

嘿,我其實還在爲此而苦苦掙扎。我嘗試了不同的動畫完全相同的代碼,並檢查發生了什麼:http://www.swfcabin.com/open/1339163406我試圖搞亂值,但似乎無法找到正確的組合。 – WgFunstorm

+0

它對我來說很好... – strah