O'Reilly logo

Cocos2d for iPhone 0.99 Beginner's Guide by Pablo Ruiz

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 - animating the stone falling

In the last chapter we wrote the code for eliminating stones and then made them fall instantaneously. This was fine for our purposes, but it looks pretty bad in practice. A distracted player may not notice what is happening onscreen. What we need to do now is use actions to move those stones from their location to the place where they are supposed to fall. You have to make the following changes to the existing code:

  1. In the moveStonesDown method, change the code that sets the stones positions, to use actions as follows:
    if(nilCount >0 && !d.disappearing)
    {
    [d.mySprite runAction:[CCMoveTo actionWithDuration: (0.5 * nilCount)/3 position:ccp(42*i + GRID_OFFSET.x,42* (j-nilCount) + GRID_OFFSET.y)]];
    }
    
  2. Below ...

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