简体   繁体   English

AS3-缩放手势获取缩放方向?

[英]AS3 - zoom gesture get zoom direction?

I've been searching for a way to do what seems like a very simple task. 我一直在寻找一种方法来完成似乎很简单的任务。 I have a mousewheel zoom function which works perfectly because the delta value is reset to 0 after each function. 我有一个鼠标滚轮缩放功能,由于每个功能后的增量值都重置为0,因此可以完美运行。 The zoom gesture it seems is not so simple? 缩放手势似乎不是那么简单吗? My issue is that I'm trying to create a dynamic scale limit (max zoom will be different for each level). 我的问题是,我正在尝试创建动态比例限制(每个级别的最大缩放都会有所不同)。 and the zoom is getting stuck at the max scale that I'm setting and can't be zoomed out. 并且缩放卡在了我设置的最大比例上,无法缩小。 I'm trying to use the e.scaleX property to identify the direction so that you can zoom out, but it's not working properly. 我正在尝试使用e.scaleX属性来确定方向,以便可以缩小,但是它无法正常工作。

Thanks for any help! 谢谢你的帮助! the code: 编码:

Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM , onZoom); 
function onZoom (e:TransformGestureEvent):void{ 
    var zoomAmountGesture:Number = 0;
    zoomAmountGesture = e.scaleX;

    if (zoomAmountGesture <= 0){
container.scaleX *= e.scaleX;
container.scaleY *= e.scaleY;
        if (container.scaleX < 1){
            container.scaleX = 1;
            container.scaleY = 1
        }
    }
    if (zoomAmountGesture > 0){
    container.scaleX *= e.scaleX;
    container.scaleY *= e.scaleY;
        if(4* BlockSize * container.scaleX > StageWidth){
            trace("zoom too big");
            var newBlockScale:Number = StageWidth / 3;
            var newBoardScale:Number = newBlockScale / BlockSize;
            trace("newBoardScale = " + newBoardScale);
            container.scaleX = newBoardScale;
            container.scaleY = newBoardScale;
        }
    }
}

I had a quick read of TransformGestureEvent . 我快速阅读了TransformGestureEvent

The next block has no meaning, because the event scaleX and scaleY properties are 1-based: 下一个块没有意义,因为事件scaleXscaleY属性基于1:

if (zoomAmountGesture <= 0){

Then, you should probably start with the following: 然后,您可能应该从以下内容开始:

function onZoom (e:TransformGestureEvent):void
{
    var aScale:Number = container.scaleX * e.scaleX;
    if (aScale < 1) aScale = 1;
    if (aScale > PredefinedMaxScale) aScale = PredefinedMaxScale;

    container.scaleX = aScale;
    container.scaleY = aScale;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM