Game Development Reference
In-Depth Information
Time for action - swapping the gems and
looking for matches
The swapping logic is found in GameScene in the swapGemsToNewPosition meth-
od:
1. The swapGemsToNewPosition method makes one call to GridAnima-
tions to animate the swap between the selected and target gem. Once this anima-
tion is complete, we fire a onNewSwapComplete 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.type
The call back switches the gems around inside the grid
array.
self.combos = 0
self.addingCombos = true
Search WWH ::




Custom Search