2012-06-08 119 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