Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3滑动手势响应性不强_Actionscript 3_Swipe_Gesture - Fatal编程技术网

Actionscript 3 AS3滑动手势响应性不强

Actionscript 3 AS3滑动手势响应性不强,actionscript-3,swipe,gesture,Actionscript 3,Swipe,Gesture,我来了: 我正在用AS3-AIR做这个移动应用 屏幕中央显示一副扑克牌,使用手指,您可以通过刷卡动作弹开上面的扑克牌以显示下一张扑克牌 这是鸟瞰图,所以只显示一张卡,用户将假定卡组的其余部分在顶卡下方 卡片正面朝下,因此每次用户从屏幕上刷下卡片时,相同的背面图像会一遍又一遍地显示在中间 当用户双击一张卡片的背面时,它会翻转过来,并露出卡片的正面 这是我的代码(我的问题紧跟其后): 以下是我的两个主要问题: -1- 刷卡姿势的反应不是很灵敏:四到五次刷卡中有一次,什么也没发生。我必须做两次刷卡动作

我来了:

我正在用AS3-AIR做这个移动应用

屏幕中央显示一副扑克牌,使用手指,您可以通过刷卡动作弹开上面的扑克牌以显示下一张扑克牌

这是鸟瞰图,所以只显示一张卡,用户将假定卡组的其余部分在顶卡下方

卡片正面朝下,因此每次用户从屏幕上刷下卡片时,相同的背面图像会一遍又一遍地显示在中间

当用户双击一张卡片的背面时,它会翻转过来,并露出卡片的正面

这是我的代码(我的问题紧跟其后):

以下是我的两个主要问题:

-1- 刷卡姿势的反应不是很灵敏:四到五次刷卡中有一次,什么也没发生。我必须做两次刷卡动作,有时甚至更多,才能最终将卡弹掉

我删除了双击侦听器,以防与手势侦听器冲突,问题仍然存在

是不是标准的AS3手势监听器性能不佳

理想情况下,滑动手势应该与TINDER应用程序中的一样:非常灵敏(并带有拖动动作)

除了标准的手势刷解决方案,还有其他选择吗

对我上面的代码有什么建议吗

-2- 如果用户刷卡速度非常快,则会刷掉第二张卡(第一张卡下方),而不是第一张卡。我怎样才能避免呢

非常感谢你的想法,也感谢你的阅读


二月十日更新


因此,我听从了马克·诺尔的建议(见下面的答案),使用了鼠标向下&鼠标向上事件处理程序,而不是滑动手势处理程序

结果更好,但并不完美

结果更好,因为鼠标按下时发生的拖动解决了第二张卡飞出屏幕的问题

结果并不完美,因为鼠标按下/鼠标按下事件与双击事件之间存在冲突:当我双击一张卡时,两次点击都被检测为卡的两次微拖动,但也被检测为双击动作

因此,我做了以下工作:

  • 要使卡片朝屏幕边缘清晰而大的拖动,松开鼠标/手指时,卡片将从屏幕上剪下

  • 对于卡的小阻力,将卡夹回其原始位置。这样,在卡被双击的情况下,翻转将从卡的原始位置发生

我仍然面临以下问题:

  • 为什么在ANDROID AIR编译的应用程序中,会检测到双击,而在windows flash player上却没有检测到双击

  • 有没有办法解决“双击”和“单击”事件之间的冲突?(可能是通过延迟拖动操作,直到系统确保不发生双击?)

    backBlue1.addEventListener(MouseEvent.MOUSE\u DOWN,mouseDownHandler);
    backBlue2.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
    backBlue1.addEventListener(MouseEvent.MOUSE\u UP,mouseHandler);
    backBlue2.addEventListener(MouseEvent.MOUSE\u UP,mouseHandler);
    backBlue1.addEventListener(MouseeEvent.双击,cardFlipper);
    Backblue 2.addEventListener(MouseeEvent.双击,cardFlipper);
    函数mouseDownHandler(e:MouseEvent):void
    {
    e、 target.startDrag();
    }
    函数MouseHandler(e:MouseEvent):void
    {
    e、 target.stopDrag();
    ecartX=initialX2-e.target.x;//ecartX是最终卡位置与原始卡位置的距离。
    如果(Math.abs(ecartX)limitX)//长时间拖动,则该卡将从屏幕上剪下
    {
    //向左滑动
    如果(ecartX>0)
    {
    randomX=Math.floor(Math.random()*(randomMaxX-randomMinX+1))+randomMinX;
    } 
    //向右滑动
    如果(ecartX<0)
    {
    randomX=数学地板(Math.random()*(randomMaxX2-randomMinX2+1))+randomMinX2;
    } 
    randomY=Math.floor(Math.random()*(randomMaxY-randomMinRotation+1))+randomMinY;
    randomRotation=Math.floor(Math.random()*(randomMaxRotation-randomMinRotation+1))+randomMinRotation;
    var tl15=新的TimelineMax();
    tl15.添加标签(“屏幕上的卡片”);
    如果(e.target==backBlue1)
    {
    tl15.to(e.target,1,{y:randomY,x:randomX,rotation:randomRotation,ease:Circ.easeOut});
    tl15.to(backBlue2,0,{y:initialY2,x:initialX2,旋转:0,ease:Linear.easeNone},“-=1”);
    tl15.添加标签(“屏幕外卡片”,“-=0.5”);
    tl15.addCallback(播放幻灯片,“屏幕上的卡片”);
    tl15.addCallback(互换,“屏幕外的卡片”);
    }   
    如果(e.target==backBlue2)
    {
    tl15.to(e.target,1,{y:randomY,x:randomX,rotation:randomRotation,ease:Circ.easeOut});
    tl15.to(backBlue1,0,{y:initialY2,x:initialX2,旋转:0,ease:Linear.easeNone},“-=1”);
    tl15.添加标签(“屏幕外卡片”,“-=0.5”);
    tl15.addCallback(播放幻灯片,“屏幕上的卡片”);
    tl15.addCallback(互换,“屏幕外的卡片”);
    }       
    }           
    }
    公共功能卡片翻页器(e:MouseeEvent)
    {
    //...
    }
    
  • 你可以考虑进行自己的刷卡检测。基本上,您在向下注册一个起始点,并检查端点是否在向上更大,然后向右滑动。当然,对于向左滑动,另一端的位置较低。 拖动时,将卡移动到触摸位置,然后向上移动,将卡移动到所需的目标位置

    我还将在当前卡片下面的卡片上禁用用户交互(mouseeEnabled,mouseChildren to false?),启用
    //Adding three same backs of cards to the stage:
    addChild(backBlue3); //No event listener will be attached to this card
    addChild(backBlue2);
    addChild(backBlue1);
    //backBlue1 and backBlue2 will alternate their Indexes/depths to create the illusion of an infinite deck of cards. So, when backBlue1 is thrown out of the screen, backBlue2 immediately fills the center of screen.
    
    Multitouch.inputMode = MultitouchInputMode.GESTURE;
    backBlue1.addEventListener(TransformGestureEvent.GESTURE_SWIPE, backCard_handler_swipe);
    backBlue2.addEventListener(TransformGestureEvent.GESTURE_SWIPE, backCard_handler_swipe);
    
    backBlue1.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);
    backBlue2.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);
    
    public function backCard_handler_swipe(e:TransformGestureEvent):void
        {
            //*********************************** Setting the random positions for swiped off cards *********************************** 
            //Swipe is done towards the left
            if (e.offsetX == -1) 
            {
                randomX = Math.floor(Math.random() * (randomMaxX - randomMinX + 1)) + randomMinX;
            } 
            //Swipe is done towards the right
            if (e.offsetX == 1) 
            {
                randomX = Math.floor(Math.random() * (randomMaxX2 - randomMinX2 + 1)) + randomMinX2;
            } 
            randomY = Math.floor(Math.random() * (randomMaxY - randomMinRotation + 1)) + randomMinY;
            randomRotation = Math.floor(Math.random() * (randomMaxRotation - randomMinRotation + 1)) + randomMinRotation;
    
    
            //*********************************** Creating a GreenSock TimeLineMax timeline to tween the "ejected" card *********************************** 
            var tl15 = new TimelineMax();
            tl15.addLabel("cardOnScreen"); //At this point of the Timeline (the very beginning), a "Swiping sound" will be played.
    
            if (e.target == backBlue1)
            {           
                //backBlue1 is tweened off the screen
                tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
    
                //backBlue2 is instantly placed in the center of the screen, behind backBlue1
                tl15.to(backBlue2, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
                tl15.addLabel("cardOffScreen", "-=0.5"); //The exact middle of the backBlue1 tween animation
                tl15.addCallback(playSlide, "cardOnScreen"); //Playing the "Swiping Sound". 
                tl15.addCallback(swapingBacks, "cardOffScreen"); //swapingBacks function is called to place backBlue2 on top of backBlue1
            }   
    
            if (e.target == backBlue2)
            {
                tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
                tl15.to(backBlue1, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
                tl15.addLabel("cardOffScreen", "-=0.5");
                tl15.addCallback(playSlide, "cardOnScreen");
                tl15.addCallback(swapingBacks, "cardOffScreen");
            }               
        }
    
    
    public function swapingBacks()
        {
            swapChildren(backBlue1, backBlue2);
        }
    
    public function cardFlipper(e:MouseEvent)
        {
            //Flipping of the card is working fine
        }
    
    backBlue1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    backBlue2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    backBlue1.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    backBlue2.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
    
    backBlue1.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);
    backBlue2.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);   
    
    function mouseDownHandler(e:MouseEvent):void
    {
        e.target.startDrag();
    }
    
    function mouseUpHandler(e:MouseEvent):void
    {
         e.target.stopDrag();
         ecartX = initialX2 - e.target.x; //ecartX is the distance of the final card position with the original one.
    
    if (Math.abs(ecartX) < limitX) //For a very small drag, the card is tweened back to its initial place
    {
        var tl25 = new TimelineMax();
        tl25.to(e.target, 0.5, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=0");
    }
    
    if (Math.abs(ecartX) > limitX) //For a clear long drag, the card is tweened off the screen
    {
        //Swipe to the left
        if (ecartX > 0) 
            {
                randomX = Math.floor(Math.random() * (randomMaxX - randomMinX + 1)) + randomMinX;
            } 
    
        //Swipe to the right
        if (ecartX < 0) 
            {
                randomX = Math.floor(Math.random() * (randomMaxX2 - randomMinX2 + 1)) + randomMinX2;
            } 
    
        randomY = Math.floor(Math.random() * (randomMaxY - randomMinRotation + 1)) + randomMinY;
        randomRotation = Math.floor(Math.random() * (randomMaxRotation - randomMinRotation + 1)) + randomMinRotation;
    
        var tl15 = new TimelineMax();
        tl15.addLabel("cardOnScreen");
    
    
        if (e.target == backBlue1)
            {
                tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
                tl15.to(backBlue2, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
                tl15.addLabel("cardOffScreen", "-=0.5");
                tl15.addCallback(playSlide, "cardOnScreen");        
                tl15.addCallback(swapingBacks, "cardOffScreen");
            }   
    
        if (e.target == backBlue2)
            {
                tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
                tl15.to(backBlue1, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
                tl15.addLabel("cardOffScreen", "-=0.5");
                tl15.addCallback(playSlide, "cardOnScreen");
                tl15.addCallback(swapingBacks, "cardOffScreen");
            }       
    }           
    }
    
    public function cardFlipper(e:MouseEvent)
    {
     //...
    }