Game Development Reference
In-Depth Information
table.insert(newColumn, 1, column[i])
end
i = i+1
end
self.grid[c] = newColumn
end
self.gridAnimations:animateCollapse
(onGridCollapseComplete)
end
3. But now, let's code the callback of that animation called onGridCol-
lapseComplete . So above the code we've entered already inside col-
lapseGrid , we add the local function:
local function onGridCollapseComplete (sender)
local function onMatchedAnimatedOut (sender)
self:collapseGrid()
end
for i = 1, #self.allGems do
local gem = self.allGems[i]
local xIndex = math.ceil ((gem:getPositionX()
- constants.TILE_SIZE * 0.5) / (constants.TILE_SIZE
+ constants.GRID_SPACE))
local yIndex = math.ceil ((gem:getPositionY()
- constants.TILE_SIZE * 0.5) / (constants.TILE_SIZE
+ constants.GRID_SPACE))
self.gridGemsColumnMap[xIndex][yIndex] = gem
self.grid[xIndex][yIndex] = gem.type
end
First, we update the array of sprites, sorting them by the new x and y indexes of
the grid.
4. Then, we check for matches again. Remember that this callback runs after the
grid collapse animation has finished, which means new gems have been added
already and these may create new matches (we'll look at the logic soon):
if (self.gridController:checkGridMatches () == true)
then
--animate matched games
Search WWH ::




Custom Search