【问题标题】:How to detect two-finger tap using Corona SDK?如何使用 Corona SDK 检测两指轻敲?
【发布时间】:2013-05-16 09:30:19
【问题描述】:

如何检测何时用两根手指轻按?点击事件可以告知点击次数,但不能告知事件中涉及的触摸次数。有什么办法可以弄清楚吗?我在我的 Corona 应用程序中启用了多点触控。我有一个应用程序可以模拟单指点击的鼠标左键单击。并且,双击鼠标右键单击。

编辑

总结并希望澄清一下,我想:

  1. 用我的食指点击一次以模拟鼠标左键单击我的应用程序。也就是说,1 次触摸,1 次点击。
  2. 用我的食指和中指同时点击一次以模拟鼠标右键单击我的应用程序。也就是说,同时触摸 2 次,轻按 1 次。

以下是 Corona 员工在他们的论坛中对我的问题所说的话: http://forums.coronalabs.com/topic/35037-how-to-detect-two-finger-tap-in-corona

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    你可以这样做:

    function object:tap( event )
        if (event.numTaps >= 2 ) then
          print( "The object was double-tapped." )
        end
    end
    object:addEventListener( "tap" )
    

    有关电晕中的对象/屏幕点击的更多详细信息,see this...

    继续编码............ :)

    【讨论】:

    • 谢谢,但不幸的是,这只是告诉你有 2 个水龙头,即一个接一个。我所追求的是知道在技术上用 2 个手指敲击 1 个。我说技术上是因为如果你同时用两根手指点击,两个事件中的每一个的 event.time 都将非常接近但不相同。也许我的问题不够清楚,我会编辑澄清。
    【解决方案2】:

    就像 Corona 的 Brent Sorrentino 所说:你应该使用多点触控。

    先看看这个http://docs.coronalabs.com/api/event/touch/id.html
    你已经可以自己做。 这是我的实现:

    system.activate( "multitouch" )
    
    local object = display.newImage( "ball.png" )
    object.numTouches = 0
    
    function object:touch( event )
        if event.phase == "began" then
            display.getCurrentStage():setFocus( self, event.id )
    
            self.numTouches = self.numTouches + 1
    
        elseif event.phase == "cancelled" or event.phase == "ended" then
            if self.numTouches <= 1 then
                print( "This is a Left click" )
                --call your onLeftClickFunction here
            end
    
            if self.numTouches == 2 then
    
                print( "This is a Right click" )
                --call your onRightClickFunction here
            end
            self.numTouches = 0
            display.getCurrentStage():setFocus( nil )
        end
        return true
    end
    object:addEventListener( "touch", object )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      相关资源
      最近更新 更多