Game Development Reference
In-Depth Information
Time for action - animating matches and
collapses
Now for the last bit of logic: the final animations:
1. 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.
2. 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 the places of the first selected gem and the target gem.
3. Then, we add the animations we run for matched gems:
Search WWH ::




Custom Search