首页 文章

如何使用Corona SDK检测双指点击?

提问于
浏览
1

如何用两根手指检测水龙头?点击事件可以告诉点击次数,但不能告诉事件涉及多少次触摸 . 有什么方法可以搞清楚吗?我在Corona App中启用了多点触控功能 . 我有一个模拟单指点击左键鼠标点击的应用程序 . 并且,双击鼠标右键单击鼠标 .

EDIT

总结并希望澄清,我想:

  • 用我的食指点击一次以模拟我的应用程序上的鼠标左键单击 . 也就是说,1次触摸,1次点击 .

  • 同时点击我的索引和中指,模拟我的应用程序上的鼠标右键单击 . 也就是说,同时进行2次触摸,1次点击 .

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

2 回答

  • 0

    你可以这样做:

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

    有关电晕中物体/屏幕水龙头的更多详细信息,see this...

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

  • 0

    就像来自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 )
    

相关问题