Game Development Reference
In-Depth Information
self:playFX("wrong.wav")
end
At the end of each new animation, be it the match one or the swap back one, we
once again run callbacks listed at the top of the method. The most important thing
these do is the call to
collapseGrid
done when the matched gems finish an-
imating inside the
onMatchedAnimatedOut
callback:
self.selectedGem = nil
self.targetGem = nil
end
We end the callback by clearing the selected gems and start with a clean slate.
3. And here, at the end of the function, we call the swap gems animation with
onNewSwapComplete
as its callback:
self.gridAnimations:swapGems (self.selectedGem,
self.targetGem, onNewSwapComplete)
end
4. Let's move back to
GridController
and add the
checkGridMatches
method. This is broken into three parts:
function GridController:checkGridMatches ()
self.matchArray = {}
for c = 1, constants.GRID_SIZE_X do
for r = 1, constants.GRID_SIZE_Y do
self:checkTypeMatch(c,r)
end
end
if (#self.matchArray >= 2) then
self.gameLayer:addToScore()
return true
end
print("no matches")
return false
end
This method starts the check by running
checkTypeMatch
on each cell.