local MainScene = class("MainScene", function()
return display.newScene("MainScene")
end)
function MainScene:ctor()
self.layer = cc.Layer:create()
cc.ui.UILabel.new({
UILabelType = 2, text = "Hello, World", size = 64})
:align(display.CENTER, display.cx, display.cy)
:addTo(self)
self.map = cc.TMXTiledMap:create("test.tmx")
self.layer:addChild(self.map, 0,1)
self.layer:addTo(self)
local function onTouchesMoved(touches, event )
--dump(event)
local n=#touches
local diff = touches[1]:getDelta()
local node = self.layer:getChildByTag(1)
local currentPosX, currentPosY= node:getPosition()
node:setPosition(cc.p(currentPosX + diff.x, currentPosY + diff.y))
end
local listener = cc.EventListenerTouchAllAtOnce:create()
--关键的地方handler(self,self.onTouchesMoved1),直接设置listener:registerScriptHandler(self.onTouchesMoved1,cc.Handler.EVENT_TOUCHES_MOVED) 运行时会出错
listener:registerScriptHandler(handler(self,self.onTouchesMoved1),cc.Handler.EVENT_TOUCHES_MOVED)local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self.layer)
end
function MainScene:onTouchesMoved1(touches, event )
--dump(event)
local n=#touches
local diff = touches[1]:getDelta()
local node = self.layer:getChildByTag(1)
local currentPosX, currentPosY= node:getPosition()
node:setPosition(cc.p(currentPosX + diff.x, currentPosY + diff.y))
end
function MainScene:onEnter()
end
function MainScene:onExit()
end
return MainScene