Game Development Reference
In-Depth Information
Time for action - creating our game scene
The GameScene class is already added to the start project and some of the code is already
in place. We'll focus first on building the game's interface and listening to touches:
1. Let's work on the addTouchEvents method:
function GameScene:addTouchEvents()
local bg = cc.Sprite:create("background.jpg")
bg:setPosition(self.middle.x, self.middle.y)
self:addChild(bg)
local function onTouchBegan(touch, event)
self.gridController:onTouchDown(touch:getLocation())
return true
end
local function onTouchMoved(touch, event)
self.gridController:onTouchMove(touch:getLocation())
end
local function onTouchEnded(touch, event)
self.gridController:onTouchUp(touch:getLocation())
end
local listener =
cc.EventListenerTouchOneByOne:create()
listener:registerScriptHandler
(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
listener:registerScriptHandler
(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
listener:registerScriptHandler
(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
local eventDispatcher = bg:getEventDispatcher()
Search WWH ::




Custom Search