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

cocos2dxlua 触屏事件

时间:2015-02-28 00:05:47      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

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

 

cocos2dxlua 触屏事件

标签:

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

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