O'Reilly logo

Cocos2d-x by Example : Beginner's Guide - Second Edition by Roger Engelbert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – swapping the gems and looking for matches

The swapping logic is found in GameScene in the swapGemsToNewPosition method:

  1. The swapGemsToNewPosition method makes one call to GridAnimations to animate the swap between the selected and target gem. Once this animation 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] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required