quick 关于触摸的问题
生活随笔
收集整理的這篇文章主要介紹了
quick 关于触摸的问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
以前遇到一個問題就是,如果觸摸層不在最后,會導致觸摸失效。這是由于下面添加的層擋住了觸摸層,而后添加的層會位于上面,默認是不可點擊,點擊不可穿透的。所以我們必須將觸摸層放置到最上面。
Logic.lua
local Logic = class("Logic",function ()return display.newLayer() end )function Logic:ctor()self:addNodeEventListener(cc.NODE_ENTER_FRAME_EVENT, handler(self, self.update))self:scheduleUpdate() endfunction Logic:update(dt)print("Logic") endreturn LogicTouch.lua
local Touch = class("Touch",function ()return display.newLayer() end )function Touch:ctor()self:setTouchEnabled(true)self:setTouchSwallowEnabled(false)self:addNodeEventListener(cc.NODE_TOUCH_EVENT, handler(self, self.touchTouch))--self:addNodeEventListener(cc.NODE_ENTER_FRAME_EVENT, handler(self, self.update))self:scheduleUpdate() endfunction Touch:touchTouch( event )if( event.name == "began" ) thenprint("began")return trueendif( event.name =="moved" ) thenprint("moved")endif( event.name =="ended" ) thenprint("ended")end endfunction Touch:update(dt)print("Touch") endreturn TouchMainScene.lua 可以
local MainScene = class("MainScene", function()return display.newScene("MainScene") end)function MainScene:ctor()local Logic=require("src.app.scenes.Logic")local logic=Logic.new()self:addChild(logic)local Touch=require("src.app.scenes.Touch")local touch=Touch.new()self:addChild(touch) endfunction MainScene:onEnter() endfunction MainScene:onExit() endreturn MainScene修改為下面這個不可以。
function MainScene:ctor()local Touch=require("src.app.scenes.Touch")local touch=Touch.new()self:addChild(touch)local Logic=require("src.app.scenes.Logic")local logic=Logic.new()self:addChild(logic)end修改為下面這個可以。
function MainScene:ctor()local Touch=require("src.app.scenes.Touch")local touch=Touch.new()self:addChild(touch,10)local Logic=require("src.app.scenes.Logic")local logic=Logic.new()self:addChild(logic)end轉載于:https://www.cnblogs.com/yufenghou/p/4565695.html
總結
以上是生活随笔為你收集整理的quick 关于触摸的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UI控件问题和XCode编译警告和错误解
- 下一篇: 盘点全国校训