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:
- 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...