Time for action – changing the grid with GridController
The GridController
object initiates all grid changes since it's where we handle touches. In the game, the user can drag a gem to swap places with another, or first select the gem they want to move and then select the gem they want to swap places with in a two-touch process. Let's add the touch handling for that:
- In
GridController
, let's add the logic toonTouchDown
:function GridController:onTouchDown (touch) if (self.gameLayer.running == false) then local scene = require("GameScene") local gameScene = scene.create() cc.Director:getInstance():replaceScene(gameScene) local bgMusicPath = cc.FileUtils:getInstance():fullPathForFilename("background.mp3") cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath, true) return end
If we are displaying the game over screen, restart the scene.
- Next, we find the gem the user is trying to select:
...