Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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] =  self.targetGem
            self.grid[self.targetIndex.x][self.targetIndex.y] =  self.selectedGem.type
            self.grid[self.selectedIndex.x][self.selectedIndex.y] =  self.targetGem.type...