2012-09-24 59 views
1

以下代碼將加載狀態爲喬治亞州時的父剪輯「mapcontainer.themap」居中。然而,當我嘗試縮放mapcontainer.themap時,它並沒有圍繞格魯吉亞的中心進行縮放。縮放時,我如何將格魯吉亞放在中心位置?AS3將家長mc的中心縮放到兒童mc的中心

//This sets the parent clip so it's centered on the child "georgia" clip on load 
var yValue:Number = mapcontainer.themap.georgia.y; 
var xValue:Number = mapcontainer.themap.georgia.x; 
var xDiff:Number = mapcontainer.themap.width/2; 
var yDiff:Number = mapcontainer.themap.height/2; 
if (xDiff > stage.stageWidth/2 || yDiff > stage.stageHeight/2) { 
    xValue = -xValue; 
    yValue = -yValue; 
} 
mapcontainer.themap.x = xValue; 
mapcontainer.themap.y = yValue; 

//This line? 
mapcontainer.themap.scaleX = mapcontainer.themap.scaleY = 2; 

回答

1

這裏是here

protected function scaleAround(objectToScale:DisplayObject, scalePoint:Point, scaleAmount:Number):void { 
    // scaling will be done relatively 
    var relScaleX:Number = scaleAmount/objectToScale.scaleX; 
    var relScaleY:Number = scaleAmount/objectToScale.scaleY; 
    // map vector to centre point within parent scope 

    scalePoint = objectToScale.localToGlobal(scalePoint); 
    scalePoint = objectToScale.parent.globalToLocal(scalePoint); 
    // current registered postion AB 
    var AB:Point = new Point(objectToScale.x, objectToScale.y); 
    // CB = AB - scalePoint, objectToScale vector that will scale as it runs from the centre 
    var CB:Point = AB.subtract(scalePoint); 
    CB.x *= relScaleX; 
    CB.y *= relScaleY; 
    // recaulate AB, objectToScale will be the adjusted position for the clip 
    AB = scalePoint.add(CB); 
    // set actual properties 
    objectToScale.scaleX *= relScaleX; 
    objectToScale.scaleY *= relScaleY; 
    objectToScale.x = AB.x; 
    objectToScale.y = AB.y; 
} 

因此,對於您的方案獲得的功能,你可以這樣做:

scaleAround(mapcontainer.themap,new Point(mapcontainer.themap.georgia.x,mapcontainer.themap.georgia.y),2) 
+0

嗨,所有的剪輯有自己的註冊點在中心 – lgriffin

+0

啊,我明白你現在在做什麼。請原諒我的回答太快。我會在幾分鐘後更新。您想放大地圖上的特定點,而不是地圖的中心。 – BadFeelingAboutThis

+0

你需要註冊中心嗎?或者只是爲了讓這更容易? – BadFeelingAboutThis