• quick cocos 多点触控,真机测试成功


    local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")
    
    local TestScene = class("TestScene", function()
        return display.newScene("TestScene")
    end)
    
    function TestScene:ctor()
        self.cursors = {}
        
        
        
        self.sprite=display.newSprite("background.png",display.cx,display.cy):addTo(self)
        self.sprite:setTouchEnabled(true)
        self.sprite:setTouchMode(cc.TOUCH_MODE_ALL_AT_ONCE)
        self.sprite:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event)
    
            if event.name == "began" or event.name == "added" then
                for id, point in pairs(event.points) do
                    local cursor=point
                    self.cursors[id] = cursor
                end
            elseif event.name == "moved" then
    
            elseif event.name == "removed" then
                for id, point in pairs(event.points) do
                    --self.cursors[id]:removeSelf()
                    --self.cursors[id]
                    self.cursors[id] = nil
                end
            else
                --[[
                for _, cursor in pairs(self.cursors) do
                    cursor:removeSelf()
                end
                ]]
                self.cursors = {}
            end
    
    
            if event.name == "ended" or event.name == "cancelled" then
    
            end
    
            return true
        end)
        
        cc.ui.UILabel.new({
            UILabelType = 2, text = "QuickGame3", size = 64})
            :align(display.CENTER, display.cx, display.cy+80)
            :addTo(self)
        
        self.label=cc.ui.UILabel.new({
            UILabelType = 2, text = "Hello, World", size = 64})
            :align(display.CENTER, display.cx, display.cy)
            :addTo(self)
        
        -- add listener
        self:addNodeEventListener(cc.NODE_ENTER_FRAME_EVENT,handler(self , self.update))
        self:scheduleUpdate()
    end
    
    
    function TestScene:update( dt )
        local sum=0
        for id, point in pairs(self.cursors) do
            sum=sum+1
        end
        self.label:setString(tostring(sum))
    end
    
    return TestScene
  • 相关阅读:
    小程序隐藏或自定义 scroll-view滚动条
    小程序携带参数(单个或多个)跳转页面(实例)
    小程序接收from表单数据(实例)
    js返回上一页
    项目部署到线上后台进不去
    微信小程序取消button边框线
    阿里iconfont图库官网网址
    php 发送邮件(实例)
    PHP 数组序列化,转为字符串
    面向对象的设计原则
  • 原文地址:https://www.cnblogs.com/yufenghou/p/4451733.html
Copyright © 2020-2023  润新知