0
我与我放大闪光灯的图像混合。我有一切工作,只有我想要点击X和Y的协调中心到舞台。 (所以点击的区域总是放大并将区域定位到舞台中间) 图像是一个动画片段,它用一个补间进行放大,但我试过一切,但图像不会居中舞台。设置放大鼠标点击目标到舞台的中心
有没有人有一个线索,我可以用来做到这一点?
我的代码是:
const TWEEN_IN:String = "tweenIn";
const TWEEN_OUT:String = "tweenOut";
var tweenDirection:String;
var internalPoint:Point;
var externalPoint:Point;
var tw:Tween;
square.x = stage.stageWidth - square.width/2;
square.y = stage.stageHeight - square.height/2;
square.addEventListener(MouseEvent.CLICK, zoomIn);
function zoomIn($e:MouseEvent):void
{
square.removeEventListener(MouseEvent.CLICK, zoomIn);
//internalPoint = new Point(stage.width/2, stage.height/2);
internalPoint = new Point(square.mouseX, square.mouseY);
//externalPoint = new Point(500, 350);
externalPoint = new Point(stage.mouseX, stage.mouseY);
tweenDirection = TWEEN_IN;
tw = new Tween(null, "", Strong.easeOut, square.scaleX, 3, 1, true);
tw.addEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
tw.addEventListener(TweenEvent.MOTION_FINISH, _cleanTween);
}
function _syncScale($e:TweenEvent):void
{
square.scaleX = square.scaleY = tw.position;
var matrix:Matrix = square.transform.matrix;
MatrixTransformer.matchInternalPointWithExternal(matrix, internalPoint, externalPoint);
square.transform.matrix = matrix;
}
function _cleanTween($e:TweenEvent):void
{
tw.removeEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
tw.removeEventListener(TweenEvent.MOTION_FINISH, _cleanTween);
tw = null;
if(tweenDirection == TWEEN_IN)
stage.addEventListener(MouseEvent.CLICK, zoomOut);
else if(tweenDirection == TWEEN_OUT)
square.addEventListener(MouseEvent.CLICK, zoomIn);
}
function zoomOut($e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.CLICK, zoomOut);
//internalPoint = new Point(0, 0);
//externalPoint = new Point(0, 0);
externalPoint = square.localToGlobal(internalPoint);
internalPoint = square.globalToLocal(externalPoint);
tweenDirection = TWEEN_OUT;
tw = new Tween(null, "", Strong.easeOut, square.scaleX, 1, 1, true);
tw.addEventListener(TweenEvent.MOTION_CHANGE, _syncScale);
tw.addEventListener(TweenEvent.MOTION_FINISH, _cleanTween);
}
好的,我试过这个,但是当注册点在左上方时,它启动了舞台中央的图像角落的动画,它仍然像以前一样放大,而没有移动它到中心。我需要以某种方式注册点击点并将这一点移到舞台中心?或?:)以及你建议的代码,是否应该放在“放大”功能中?我应该只是将其添加到原始代码中,还是删除其中的一部分?它不会工作:/ – Cat
我的代码行将替换_syncScale()方法中的最后三个,保留scaleX/scaleY定义,但替换其余部分。 – richardolsson