码迷,mamicode.com
首页 > 其他好文 > 详细

cocos3 多点触控,真机测试成功

时间:2015-04-23 21:36:48      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

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

 

cocos3 多点触控,真机测试成功

标签:

原文地址:http://www.cnblogs.com/yufenghou/p/4451733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!