本文介绍了AS3规模母公司三菱商事的中心,孩子三菱商事的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面code中心的负载状态格鲁吉亚父剪辑mapcontainer.themap。但是,当我尝试规模mapcontainer.themap,它不围绕规模格鲁吉亚的中心。如何缩放的时候我一直在佐治亚州的中心?
//这将设置父剪辑所以它集中在孩子格上载片段
变种y值:数= mapcontainer.themap.georgia.y;
VAR与xValue:数= mapcontainer.themap.georgia.x;
VAR xDiff:数= mapcontainer.themap.width / 2;
VAR yDiff:数= mapcontainer.themap.height / 2;
如果(xDiff> stage.stageWidth / 2 || yDiff> stage.stageHeight / 2){
与xValue = -xValue;
y值= -yValue;
}
mapcontainer.themap.x =与xValue;
mapcontainer.themap.y = y值;
//这一行?
mapcontainer.themap.scaleX = mapcontainer.themap.scaleY = 2;
解决方案
下面是从的
保护功能scaleAround(objectToScale:的DisplayObject,scalePoint:点,scaleAmount:编号):无效{
//比例会相对完成
VAR relScaleX:数= scaleAmount / objectToScale.scaleX;
VAR relScaleY:数= scaleAmount / objectToScale.scaleY;
//地图矢量父范围内的中心点
scalePoint = objectToScale.localToGlobal(scalePoint);
scalePoint = objectToScale.parent.globalToLocal(scalePoint);
//目前注册现在的位置是AB
变种AB:点=新的点(objectToScale.x,objectToScale.y);
// CB = AB - scalePoint,objectToScale矢量,将缩放,因为它从中心运行
变种CB:点= AB.subtract(scalePoint);
CB.x * = relScaleX;
CB.y * = relScaleY;
// recaulate AB,objectToScale将是剪辑的调整后的位置
AB = scalePoint.add(CB);
//设置实际属性
objectToScale.scaleX * = relScaleX;
objectToScale.scaleY * = relScaleY;
objectToScale.x = AB.x;
objectToScale.y = AB.y;
}
因此,对于你的情况,你可以这样做:
scaleAround(mapcontainer.themap,新点(mapcontainer.themap.georgia.x,mapcontainer.themap.georgia.y),2)
The following code centers the parent clip "mapcontainer.themap" on the state Georgia on load. However, when i try to scale mapcontainer.themap, it doesnt scale around Georgia's center. How do i keep Georgia in the center when scaling?
//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;
解决方案
Here is a function derived from 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;
}
So for your scenario, you could do this:
scaleAround(mapcontainer.themap,new Point(mapcontainer.themap.georgia.x,mapcontainer.themap.georgia.y),2)
这篇关于AS3规模母公司三菱商事的中心,孩子三菱商事的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!