Time for action – animating matches and collapses
Now for the last bit of logic: the final animations:
- We'll start with the easy ones:
function GridAnimations:animateSelected (gem) gem:select() gem:stopAllActions() local rotate = cc.EaseBounceOut:create ( cc.RotateBy:create(0.5, 360) ) gem:runAction(rotate) end
This rotates a gem; we use this animation when a gem is first selected.
- Next is the swap animation:
function GridAnimations:swapGems (gemOrigin, gemTarget, onComplete) gemOrigin:deselect() local origin = self.gameLayer.selectedGemPosition local target = cc.p(gemTarget:getPositionX(), gemTarget:getPositionY()) local moveSelected = cc.EaseBackOut:create(cc.MoveTo:create(0.8, target) ) local moveTarget = cc.EaseBackOut:create(cc.MoveTo:create(0.8, origin) ) local callback = cc.CallFunc:create(onComplete) gemOrigin:runAction(moveSelected) gemTarget:runAction (cc.Sequence:create(moveTarget, callback)) end
All this does is swap...