将一个movieclip绘制到bitmapdata会四处移动

时间:2012-06-08 12:21:11

标签: actionscript-3 flash flex

我正在尝试将一个movieclip绘制到一个bitmapdata,并让它看起来像我刚刚将movieclip直接添加到舞台上一样。然而,结果转移了。我怀疑它与原点和界限有关,但无法弄明白。

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;
        }

    }

}

1 个答案:

答案 0 :(得分: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