zoukankan      html  css  js  c++  java
  • cocos2dxlua 触屏事件

    require "Cocos2d"
    require "Cocos2dConstants"
    
    local cclog = function(...)
        print(string.format(...))
    end
    
    
    local TestScene = class("TestScene",function()
        return cc.Scene:create()
    end)
    
    function TestScene.create()
        local scene = TestScene.new()
        local sp=cc.Sprite:create("dog.png")
        sp:setPosition(100,100)
        scene:addChild(sp)
        scene:register()
        return scene
    end
    
    function TestScene:register()
    
        local function onTouchBegan(touch, event)
            local location = touch:getLocation()
            
            cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y)
            return true
        end
    
        local function onTouchMoved(touch, event)
            local location = touch:getLocation()
            cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y)
        end
    
        local function onTouchEnded(touch, event)
            local location = touch:getLocation()
            cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y)
        end
        
        local listener = cc.EventListenerTouchOneByOne:create()
        listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
        listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
        listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
        local eventDispatcher = self:getEventDispatcher()
        eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)
    end
    
    
    
    return TestScene
  • 相关阅读:
    图的深度遍历
    数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历

    满汉全席
    2-sat(模板)
    2-sat
    花匠
    维护序列NOI2005
    序列终结者
    杨辉三角
  • 原文地址:https://www.cnblogs.com/yufenghou/p/4304498.html
Copyright © 2011-2022 走看看