actionscript 3 - Drawing a movieclip to bitmapdata moves around -
i'm trying draw movieclip bitmapdata , have same if had added movieclip directly stage. result shifts around. suspect has origin , bounds can't figure out.
http://megaswf.com/s/2441986 (the 1 on right 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); // comparison, want result movieclip = new skeletonwalk(); movieclip.x = 200; movieclip.y = 200; addchild(movieclip); // , 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 movie clip in top left corner of bitmap, clip changes height when sword in upright position whole thing moves down.
try fix bottom edge, not top edge.
bitmapdata.draw(movieclip, new matrix(1, 0, 0, 1, -bounds.x, maxmcheight - (bounds.y + bounds.height))); //maxmcheight height of clip while sword risen
Comments
Post a Comment