cocos2dx 事件监听

cocos2dx 事件监听,第1张

概述local btnSp=cc.Sprite:create("icon.png") ly:addChild(btnSp) btnSp:setPosition(600,100) local function onTouchBegan(touch, event) local locationInNode = btnSp:convertT
    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 事件监听所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1054853.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存