As3 捏合缩放图片从手势保持比例来看
As3 Pinch Zoom picture from point of gesture keeping ratio
我正在使用下面的代码来缩放 In/Out + 从手势点平移,非常适合 X/Y 一起缩放手势,但如果你只做 X 或只做 Y,它会丢失比例比例。
它只是一个 MC "largeImageContainer",很容易在动画上复制 Touch 和 Gesture 上的问题。
任何帮助将不胜感激;)
import flash.events.TransformGestureEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import fl.motion.MatrixTransformer;
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
function onZoom(event: TransformGestureEvent): void {
//trace(e.localX);
var locX: Number = event.localX;
var locY: Number = event.localY;
var stX: Number = event.stageX;
var stY: Number = event.stageY;
var prevScaleX: Number = largeImageContainer.scaleX;
var prevScaleY: Number = largeImageContainer.scaleY;
var mat: Matrix;
var externalPoint = new Point(stX, stY);
var internalPoint = new Point(locX, locY);
largeImageContainer.scaleX *= event.scaleX;
largeImageContainer.scaleY *= event.scaleY;
if (event.scaleX > 1 && largeImageContainer.scaleX > 6) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
if (event.scaleY > 1 && largeImageContainer.scaleY > 6) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
if (event.scaleX < 1.1 && largeImageContainer.scaleX < 1) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
if (event.scaleY < 1.1 && largeImageContainer.scaleY < 1) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
mat = largeImageContainer.transform.matrix.clone();
MatrixTransformer.matchInternalPointWithExternal(mat, internalPoint, externalPoint);
largeImageContainer.transform.matrix = mat;
}
largeImageContainer.addEventListener(MouseEvent.MOUSE_DOWN, f_begin);
largeImageContainer.addEventListener(MouseEvent.MOUSE_UP, f_end);
function f_begin(e: MouseEvent): void {
largeImageContainer.startDrag();
}
function f_end(e: MouseEvent): void {
largeImageContainer.stopDrag();
}
实际上这就是我想要的 ;) 保持比例,因为我更关注 Y 而不是 X。
largeImageContainer.scaleX *= event.scaleY;
largeImageContainer.scaleY *= event.scaleY;
我正在使用下面的代码来缩放 In/Out + 从手势点平移,非常适合 X/Y 一起缩放手势,但如果你只做 X 或只做 Y,它会丢失比例比例。
它只是一个 MC "largeImageContainer",很容易在动画上复制 Touch 和 Gesture 上的问题。
任何帮助将不胜感激;)
import flash.events.TransformGestureEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import fl.motion.MatrixTransformer;
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
function onZoom(event: TransformGestureEvent): void {
//trace(e.localX);
var locX: Number = event.localX;
var locY: Number = event.localY;
var stX: Number = event.stageX;
var stY: Number = event.stageY;
var prevScaleX: Number = largeImageContainer.scaleX;
var prevScaleY: Number = largeImageContainer.scaleY;
var mat: Matrix;
var externalPoint = new Point(stX, stY);
var internalPoint = new Point(locX, locY);
largeImageContainer.scaleX *= event.scaleX;
largeImageContainer.scaleY *= event.scaleY;
if (event.scaleX > 1 && largeImageContainer.scaleX > 6) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
if (event.scaleY > 1 && largeImageContainer.scaleY > 6) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
if (event.scaleX < 1.1 && largeImageContainer.scaleX < 1) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
if (event.scaleY < 1.1 && largeImageContainer.scaleY < 1) {
largeImageContainer.scaleX = prevScaleX;
largeImageContainer.scaleY = prevScaleY;
}
mat = largeImageContainer.transform.matrix.clone();
MatrixTransformer.matchInternalPointWithExternal(mat, internalPoint, externalPoint);
largeImageContainer.transform.matrix = mat;
}
largeImageContainer.addEventListener(MouseEvent.MOUSE_DOWN, f_begin);
largeImageContainer.addEventListener(MouseEvent.MOUSE_UP, f_end);
function f_begin(e: MouseEvent): void {
largeImageContainer.startDrag();
}
function f_end(e: MouseEvent): void {
largeImageContainer.stopDrag();
}
实际上这就是我想要的 ;) 保持比例,因为我更关注 Y 而不是 X。
largeImageContainer.scaleX *= event.scaleY;
largeImageContainer.scaleY *= event.scaleY;