Time for action – swapping the gems and looking for matches
The swapping logic is found in GameScene
in the swapGemsToNewPosition
method:
- The
swapGemsToNewPosition
method makes one call toGridAnimations
to animate the swap between the selected and target gem. Once this animation is complete, we fire aonNewSwapComplete
method. The majority of the logic takes place in there:function GameScene:swapGemsToNewPosition () local function onMatchedAnimatedOut (sender) self:collapseGrid() end local function onReturnSwapComplete (sender) self.gridController.enabled = true end local function onNewSwapComplete (sender) self.gridGemsColumnMap[self.targetIndex.x][self.targetIndex.y] = self.selectedGem self.gridGemsColumnMap[self.selectedIndex.x][self.selectedIndex.y] = self.targetGem self.grid[self.targetIndex.x][self.targetIndex.y] = self.selectedGem.type self.grid[self.selectedIndex.x][self.selectedIndex.y] = self.targetGem...