cocos2d-x lua 触摸事件

cocos2d-x lua 触摸事件,第1张

概述cocos2d-x lua 触摸事件 version: cocos2d-x 3.6 1.监听 function GameLayer:onEnter() local eventDispatcher = self:getEventDispatcher() local function onTouchBegan(touch, event) local locationI cocos2d-x lua 触摸事件

version: cocos2d-x 3.6

1.监听
function@H_419_10@ GameLayer@H_419_10@:onEnter@H_419_10@()@H_419_10@    local@H_419_10@ eventdispatcher = self:getEventdispatcher()    local@H_419_10@ function@H_419_10@ ontouchBegan@H_419_10@(touch@H_419_10@,event@H_419_10@)@H_419_10@        local@H_419_10@ locationInNode = self:convertToNodeSpace(touch:getLocation())        local@H_419_10@ s = self:getContentSize()        local@H_419_10@ rect = cc.rect(0@H_419_10@,0@H_419_10@,s.wIDth,s.height)        if@H_419_10@ cc.rectContainsPoint(rect,locationInNode) then@H_419_10@            self:setcolor(cc.c3b(255@H_419_10@,0@H_419_10@))            return@H_419_10@ true@H_419_10@        end@H_419_10@@H_419_10@        return@H_419_10@ false@H_419_10@        end@H_419_10@@H_419_10@    local@H_419_10@ function@H_419_10@ ontouchmoved@H_419_10@(touch@H_419_10@,event@H_419_10@)@H_419_10@    end@H_419_10@@H_419_10@    local@H_419_10@  function@H_419_10@ ontouchended@H_419_10@(touch@H_419_10@,event@H_419_10@)@H_419_10@        self:setcolor(cc.c3b(255@H_419_10@,255@H_419_10@,255@H_419_10@))    end@H_419_10@@H_419_10@    local@H_419_10@ Listener = cc.EventListenertouchOneByOne:create@H_419_10@()    self._Listener@H_419_10@ = Listener    Listener:setSwallowtouches(true@H_419_10@)    Listener:registerScriptHandler(ontouchBegan,cc.Handler.EVENT_touch_BEGAN )    Listener:registerScriptHandler(ontouchmoved,cc.Handler.EVENT_touch_MOVED )    Listener:registerScriptHandler(ontouchended,cc.Handler.EVENT_touch_ENDED )    if@H_419_10@ 0@H_419_10@ == self._fixed@H_419_10@Priority then@H_419_10@        eventdispatcher:addEventListenerWithSceneGraPHPriority(Listener,self)    else@H_419_10@        eventdispatcher:addEventListenerWithFixedPriority(Listener,self._fixed@H_419_10@Priority)    end@H_419_10@@H_419_10@end@H_419_10@@H_419_10@
2.移除
function@H_419_10@ touchableSpriteWithFixedPriority:onExit@H_419_10@()@H_419_10@@H_419_10@    local@H_419_10@ eventdispatcher = self:getEventdispatcher()    eventdispatcher:removeEventListener(self._Listener)end@H_419_10@
3.注意

onEnter和onExit在lua中不会因节点别add和remove而直接被调用,当子节点被父节点add和remove时,会发送enter和exit的消息,所以需要再初始化节点的时候,监听消息,并在收到消息后调用onEnter或onExit。
http://www.jb51.cc/article/p-dqqlstfl-dp.html

总结

以上是内存溢出为你收集整理的cocos2d-x lua 触摸事件全部内容,希望文章能够帮你解决cocos2d-x lua 触摸事件所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存