美文网首页
cocos2d-x lua中给button添加点击间隔,防止重复

cocos2d-x lua中给button添加点击间隔,防止重复

作者: Kerwin_lang | 来源:发表于2017-10-20 20:08 被阅读0次

    防止按钮重复点击造成问题,给button添加一个点击间隔

        --分享按钮
        local shareBtn = self.pCenterLayout:getChildByName("Button_share")
        shareBtn.LastClickTime = os.clock()
        shareBtn:addTouchEventListener(function ( sender,eventType )
            if eventType == ccui.TouchEventType.ended then
                print("分享。。。。。")
                -- print("shareBtn.LastClickTime = ",shareBtn.LastClickTime)
                if shareBtn.LastClickTime ~= nil then
                    -- print("os.clock() = ",os.clock())
                    -- print("os.clock() - shareBtn.LastClickTime = ",os.clock() - shareBtn.LastClickTime)
                    if os.clock() - shareBtn.LastClickTime < 0.5 then
                        -- print(".......0000..........")
                        return
                    end
                end
                shareBtn.LastClickTime = os.clock()
                self:shareBtnClick()
            end
        end)
    

    相关文章

      网友评论

          本文标题:cocos2d-x lua中给button添加点击间隔,防止重复

          本文链接:https://www.haomeiwen.com/subject/eitbuxtx.html