flash as3放大(放大)到剪辑中的特定点
我试图放大一个容器/父级电影剪辑,以便有效地放大到它的一个子级引用的点。我已经知道了如何使用GlobalTopolocal将该点放在舞台的中心,但问题是容器剪辑的注册点(并且需要保持)在左上角,因此当我放大容器剪辑时,该点不会停留在屏幕的中心。这是我的密码: //修订:flash as3放大(放大)到剪辑中的特定点,flash,actionscript-3,Flash,Actionscript 3,我试图放大一个容器/父级电影剪辑,以便有效地放大到它的一个子级引用的点。我已经知道了如何使用GlobalTopolocal将该点放在舞台的中心,但问题是容器剪辑的注册点(并且需要保持)在左上角,因此当我放大容器剪辑时,该点不会停留在屏幕的中心。这是我的密码: //修订: var stageCenter = new Point(int(stage.stageWidth/2),int(stage.stageHeight)/2); var parPointLocal = parRef.glob
var stageCenter = new Point(int(stage.stageWidth/2),int(stage.stageHeight)/2);
var parPointLocal = parRef.globalToLocal(stageCenter);
TweenMax.to(treeClip,.5,{x:parPointLocal.x,y:parPointLocal.y,onComplete:doZoom});
function doZoom():void {
var zoomPoint = zoomToMember(treeClip,stageCenter,2);
function zoomToMember(target:MovieClip, center:Point, scale:Number):Point {
var m:Matrix = new Matrix();
m.translate(-center.x, -center.y);//move the center into (0,0)
m.scale(scale, scale);//scale relatively to (0,0) (which is where our center is now)
m.translate(center.x, center.y);//move the center back to its original position
return m.transformPoint(new Point());//transform (0,0) using the whole transformation matrix to calculate the destination of the upper left corner
}
TweenMax.to (treeClip,.5,{x:zoomPoint.x,y:zoomPoint.y,scaleX:2,scaleY:2})
}
当我这样做的时候,放大的点最终会出现在“梅布尔·格里尔玩具店”周围的某个地方——我想这是在树梢被修剪之前舞台的中心点,所以“乔恩·安德森”会在舞台的中心
缩放后,您需要计算左上角的目标位置,并将x和y属性连接到目标位置 最简单的方法是使用矩阵:
function scale(target:MovieClip, center:Point, scale:Number):Point {
var m:Matrix = new Matrix();
m.translate(-center.x, -center.y);//move the center into (0,0)
m.scale(scale, scale);//scale relatively to (0,0) (which is where our center is now)
m.translate(center.x, center.y);//move the center back to its original position
return m.transformPoint(new Point());//transform (0,0) using the whole transformation matrix to calculate the destination of the upper left corner
}
谢谢-我有点明白(对不起),但当我实现它时,它似乎没有缩放到正确的位置。我已经编辑了上面的描述,以显示修改后的代码。您可以提供的任何帮助都是greatOh—还有—如果movieclip(目标)未被使用,为什么要将电影剪辑作为函数的参数?应该吗?是的,包括target实际上没有用:)。但是,如果中心点实际上是在全局坐标空间中表示的,则需要执行
center=target.globaltocolal(center)代码>,这使目标再次成为必要。太棒了-谢谢!我还不确定我是否完全理解整个矩阵的概念,但你的回答肯定有帮助。