Book Image

Learning Cocos2d-x Game Development

By : Siddharth Shekar
Book Image

Learning Cocos2d-x Game Development

By: Siddharth Shekar

Overview of this book

Table of Contents (19 chapters)
Learning Cocos2d-x Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Adding the gameplay layer


In order to keep all the enemies and bullets in the same layer, we will create a new layer named GameplayLayer. This is where the gameplay will add and remove enemies and bullets, update their positions, and check for collisions. So, create a class named GameplayLayer similar to how you created the enemy class earlier.

Now, make sure that the GameplayLayer.h and GameplayLayer.cpp files are in the Classes folder. Once you have checked this, open the GameplayLayer.h file and add the following lines of code to it:

#ifndef __wp8Game__GameplayLayer__
#define __wp8Game__GameplayLayer__

#include "cocos2d.h"
using namespace cocos2d;


class GameplayLayer: public CCLayer
{
public:
    GameplayLayer();
    ~GameplayLayer();
    void update();  

private:
    CCSize visibleSize;
      CCArray* enemies;

    CCArray* getEnemiesArray();

    };

#endif /* defined(__wp8Game__GameplayLayer__) */

Here, we create a new class named GameplayLayer and inherit from CCLayer. Then, we have...