
local btnSp=cc.Sprite:create("icon.png") ly:addChild(btnSp) btnSp:setposition(600,100) local function ontouchBegan(touch,event) local locationInNode = btnSp:convertToNodeSpace(touch:getLocation()) local s = btnSp:getContentSize() local rect = cc.rect(0,s.wIDth,s.height) if cc.rectContainsPoint(rect,locationInNode) then print("------touch me--------") return true end return false end local function ontouchmoved(touch,event) print("----move----") end local function ontouchended(touch,event) print("----end----") end local eventdispatcher = ly:getEventdispatcher() local Listener = cc.EventListenertouchOneByOne:create() Listener:setSwallowtouches(true) Listener:registerScriptHandler(ontouchBegan,cc.Handler.EVENT_touch_BEGAN ) Listener:registerScriptHandler(ontouchmoved,cc.Handler.EVENT_touch_MOVED ) Listener:registerScriptHandler(ontouchended,cc.Handler.EVENT_touch_ENDED ) eventdispatcher:addEventListenerWithSceneGraPHPriority(Listener,btnSp) 总结 以上是内存溢出为你收集整理的cocos2dx 事件监听全部内容,希望文章能够帮你解决cocos2dx 事件监听所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)