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 – using parallax scrolling


The parallax scrolling technique adds depth to your game by moving different layers placed one above each other at different speed. Let's use it in our TilemapScene class and you'll see what I'm talking about. Perform the following steps:

  1. Open the TilemapScene.m file and add the following instance variable:

    @implementation TilemapScene
    {
        //..skipped..
    
        CCParallaxNode *_parallaxNode;
    }
  2. Then find the addTilemap method and replace it with the following code:

    -(void)addTilemap
    {
        _tileMap = [CCTiledMap tiledMapWithFile:@"tilemap.tmx"];
        _worldSize = _tileMap.contentSizeInPoints.width;
        
        //1
        CCTiledMapLayer *bushes = [_tileMap layerNamed:@"Bushes"];
        CCTiledMapLayer *trees = [_tileMap layerNamed:@"Trees"];
        CCTiledMapLayer *ground = [_tileMap layerNamed:@"Ground"];
    
        //2
        _parallaxNode = [CCParallaxNode node];
    
        //3
        [bushes removeFromParentAndCleanup:NO];
        [trees removeFromParentAndCleanup:NO];
        [ground removeFromParentAndCleanup...