【问题标题】:Detect how many object user touches in one touch? Corona一键检测用户触摸了多少对象?电晕
【发布时间】:2013-08-19 12:28:00
【问题描述】:

你能告诉我如何使用 Corona SDK 制作一个函数来检测一次触摸拦截/触摸多少个对象吗?

【问题讨论】:

    标签: function touch coronasdk


    【解决方案1】:

    解决这个问题的方法是为当前的触摸次数创建一个计数器:

    local counter = 0
    

    以及一个处理触摸并相应更新计数器的函数:

    local function touchHandler( event )
        if event.phase == "began" then
            counter = counter + 1
        elseif event.phase == "ended" then
            counter = counter - 1
        end
    end
    

    然后你只需为所有对象添加一个触摸监听器:

    object:addEventListener("touch", touchHandler)
    

    【讨论】:

    • 感谢您的回答,但这不是我的意思。我的意思是我想知道用户在屏幕上一键拦截了多少对象。
    • 哦,对不起。也许您应该将它们全部放在同一张表中,并根据用户交互来计算该表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 2014-10-04
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    相关资源
    最近更新 更多