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

    }

}
4

1 回答 1

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
于 2012-06-08T12:34:05.313 回答