代码设置显示对象的注册点

来源:互联网 发布:淘宝联盟上商品优惠券 编辑:程序博客网 时间:2024/04/27 21:45
public static function setRegPoint(obj:DisplayObjectContainer, newX:Number, newY:Number):void {//get the bounds of the object and the location//of the current registration point in relation//to the upper left corner of the graphical content//note: this is a PSEUDO currentRegX and currentRegY, as the//registration point of a display object is ALWAYS (0, 0):var bounds:Rectangle = obj.getBounds(obj.parent);var currentRegX:Number = obj.x - bounds.left;var currentRegY:Number = obj.y - bounds.top;var xOffset:Number = newX - currentRegX;var yOffset:Number = newY - currentRegY;//shift the object to its new location--//this will put it back in the same position//where it started (that is, VISUALLY anyway):obj.x += xOffset;obj.y += yOffset;//shift all the children the same amount,//but in the opposite directionfor(var i:int = 0; i < obj.numChildren; i++) {obj.getChildAt(i).x -= xOffset;obj.getChildAt(i).y -= yOffset;}}
这样缩放的时候,就会根据注册点来缩放了
0 0