I’m trying to draw a movieclip to a bitmapdata and have it look the same as if I had just added the movieclip directly to the stage. However the result shifts around. I suspect it has something to do with the origin and bounds but can’t figure it out.
http://megaswf.com/s/2441986
(the one on the right is the problem)
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;
}
}
}
You draw your movie clip in top left corner of the bitmap, as the clip changes its height when the sword is in the upright position whole thing moves down.
Try to fix bottom edge, not the top edge.