AS3:在adobe air android中缩放和平移动画片段

时间:2014-06-23 07:55:49

标签: actionscript-3 flash air

我在github上使用gestouch库。https://github.com/fljot/Gestouch

zoomall是我的movieclip,我能够在特定点放大和缩小。 这是我的代码,

import org.gestouch.events.GestureEvent;
import org.gestouch.gestures.ZoomGesture;

var zoom: ZoomGesture*;

zoom = new ZoomGesture(zoomall);
zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_BEGAN, onGesture);
zoom.addEventListener(org.gestouch.events.GestureEvent.GESTURE_CHANGED, onGesture);

function onGesture(event: org.gestouch.events.GestureEvent): void {

    const gesture: ZoomGesture = event.target as ZoomGesture;

    var matrix: Matrix = zoomall.transform.matrix;
    var transformPoint: Point = matrix.transformPoint(zoomall.globalToLocal(zoom.location));
    matrix.translate(-transformPoint.x, -transformPoint.y);
    matrix.scale(gesture.scaleX, gesture.scaleY);
    matrix.translate(transformPoint.x, transformPoint.y);
    zoomall.transform.matrix = matrix;
}

这里我想限制放大和缩小到特定比例。 而且我也想要平移movieclip(zoomall),它不应该在设备屏幕外平移。

2 个答案:

答案 0 :(得分:2)

如果您想尝试使用这些可以帮助您的优秀和简单的教程。

潘教程 http://www.republicofcode.com/tutorials/flash/as3pangesture/ 捏/缩放 http://www.republicofcode.com/tutorials/flash/as3pinchzoom/

希望这有帮助

答案 1 :(得分:0)

你意识到通过调用matrix.scale(B,B)你只需要做A * B = C, 其中 A 是当前比例, C 是否会产生比例? 因此,如果您不希望 C 大于最大 maxC ,则应限制 B

B = Math.min(B, maxC / A)

最小 minC

相同
B = Math.max(minC / A, B)

所以你会:

// assuming you keep the scale ratio
var minS:Number = MIN_SCALE / zoomall.scaleX;
var maxS:Number = MAX_SCALE / zoomall.scaleX;
var s:Number = Math.max(minS, Math.min(gesture.scaleX, maxS));
matrix.scale(s, s);
相关问题