如何解决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,{x:zoomPoint.x,y:zoomPoint.y,scaleX:2,scaleY:2})
}
当我这样做时,缩放点最终位于\“ Mabel Greer \'s Toy Shop \”周围的某个地方-我想这是在TreeClip补间之前舞台的中心点,因此\“ Jon Anderson \”在舞台中央
解决方法
在缩放和补间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
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。