Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – moving and following the bird


What is the purpose of the big world if we can see only a small portion of it? Let's make the bird fly forward and see the whole tile map. Perform the following steps:

  1. Open the TilemapScene.m file and add the update: method to move the tile map as follows:

    -(void)update:(CCTime)dt
    {
        float distance = 150.0f * dt;
        
        CGPoint newTilemapPos = _tileMap.position;
        newTilemapPos.x = newTilemapPos.x - distance;
        _tileMap.position = newTilemapPos;
    }
  2. You can build and run the game right now, but you will see that the bird isn't stopping when we reach the end of the tile map. So let's change the update: method to the following code:

    -(void)update:(CCTime)dt
    {
        float distance = 150.0f * dt;
        
        CGPoint newTilemapPos = _tileMap.position;
        newTilemapPos.x = newTilemapPos.x - distance;
        
        CGSize viewSize = [CCDirector sharedDirector].viewSize;
        float endX = -1 * _worldSize + viewSize.width;
        
        if (newTilemapPos.x &gt...