Game Development Reference
In-Depth Information
oinInitialPositionY);
CGFloat coinFinalPositionX = -coinSprite.size.width/
2;
CGFloat coinFinalPositionY = coinInitialPositionY;
CGPoint coinFinalPosition =
CGPointMake(coinFinalPositionX, coinFinalPositionY);
2. After that, set the initial position as the coin sprite position.
coinSprite.position = coinInitialPosition;
3. The initial position of the coin is set and now we have to animate the coin from
the initial position to the final position. This can be done by adding a move
SKAction to the coin sprite specifying its final destination.
SKAction *coinMoveAnimation = [SKAction
moveTo:coinFinalPosition duration:5.0];
[coinSprite runAction:coinMoveAnimation];
Finally, our addCoin method has been fully prepared for the game. For moving the coins
as collectables, perform the following steps:
1. For making these coins move as collectables in the scene, a little bit of refactoring
is required in the update method. Update the diffTim e and lastUp-
datedTime as shown in the following code:
if (self.lastUpdatedTime)
{
self.diffTime = currentTime -
self.lastUpdatedTime;
}
else
{
self.diffTime = 0;
}
self.lastUpdatedTime = currentTime;
Search WWH ::




Custom Search