flash as3 放大(按比例放大)到剪辑中的特定点
我正在尝试放大容器/父影片剪辑,以便有效地放大到其子级之一引用的点。我已经弄清楚如何使用 globalToLocal 来获得舞台中心的该点,但问题是容器剪辑的注册点是(并且需要保持)在左上角,所以当我缩放容器剪辑时向上时,该点不会停留在屏幕中心。这是我的代码:
//修订:
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})
}
当我这样做时,缩放点最终位于“Mabel Greer's Toy Shop”周围的某个地方 - 我想象这是在树剪辑补间之前舞台的中心点,以便“Jon Anderson”会处于舞台中央。
I'm trying to scale a container/parent movie clip up so that I effectively zoom in to a point referenced by one of its children. I've figured out how to use globalToLocal to get that point at the center of the stage, but the problem is the registration point for the container clip is (and needs to stay) at the upper left, so when I scale the container clip up, the point does not stay in the center of the screen. Here's my code:
//REVISED:
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})
}
When I do this, the zoomed point ends up being somewhere around "Mabel Greer's Toy Shop" - which I imagine was the center point of the stage before the treeClip was tweened so that "Jon Anderson" would be at the center of the stage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在缩放并补间 x 和 y 属性后计算左上角的目标位置。
最简单的方法是使用矩阵:
You need to calculate the destination position of the upper left corner after scaling and tween the x and y properties to it.
The most simple way is to use matrices: