大家帮忙看一个问题,代码如下:
如果把读取 场景 文件 注释, onTouch 的函数就能够响应
但是如果读取 场景 文件,加入 当前 Layer 后onTouch就没有响应
以为是zorder的原因,做一些测试,发现不是这个原因
大家有遇到类似的情况么?
知道GUIReader的控件需要加入到TouchGroup中,然后用addwidget添加
require("app/scenes/Hero")
TownScene = class(“TownScene”, function()
return display.newScene(“TownScene”)
end)
TownScene.rootLayer = nil
–从ccs中导出的场景的根节点
TownScene.scene_rootnode = nil
–主角
TownScene.hero = nil
function TownScene:onTouch(event, x, y)
print(event,",",x,",",",",y)
if event == “began” then
local p = CCPoint(x, y)
–self.hero:moveTo(2, x, y)
–self.player:setViewPointByPlayer()
elseif event ~= “moved” then
print(event)
end
return true
end
function TownScene:update(dt)
end
function TownScene:ctor()
–local group = TouchGroup:create()
–self:addChild(group)
self.rootLayer = display.newLayer()
self.rootLayer:setTouchEnabled(true)
self:addChild(self.rootLayer)
--读取场景
self.scene_rootnode = SceneReader:sharedSceneReader():createNodeWithSceneFile("publish/town_1.json")
self.scene_rootnode:setTouchEnabled(true)
self.rootLayer:addChild(self.scene_rootnode, 1000, 1)
--初始化hero
self.hero = Hero.create()
self.hero:bindNode(self.scene_rootnode:getChildByTag(10031))
self.hero:play("run")
--self.hero._node:setPosition(ccp(100, 200))
--self.rootLayer:setZOrder(200)
--增加touch相应
self.rootLayer:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event) return self:onTouch(event.name, event.x, event.y) end)
--帧更新事件回调函数
self:addNodeEventListener(cc.NODE_ENTER_FRAME_EVENT,function(dt) self:update(dt) end)
self:scheduleUpdate()
end
function TownScene:loadArmatureData()
–CCArmatureDataManager:sharedArmatureDataManager():addArmatureFileInfo(“armature/HeroAnimation.ExportJson”)
end
function TownScene:onEnter()
end
function TownScene:onExit()
end
return TownScene
