Adding new CCLayer

Hey guys, question time again. How do you add a new Layer in the current scene(HelloWorld) and how to add objects in it? I want to use CCLayer as the parent of my Bullet Class since CCMutableArray does not work with my current design plan.
Currently I’m looking at this tutorial http://www.raywenderlich.com/4666/how-to-create-a-hud-layer-with-cocos2d but I’m having a hardtime understanding and converting it.

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::node();

    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::node();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

Adding a new layer by ‘addChild’ function. Please refer to tests project of cocos2d-x.

Could you please direct me to the correct link, I don’t know which test projects I should be looking on github?

rv sarmiento wrote:

Could you please direct me to the correct link, I don’t know which test projects I should be looking on github?

Please go to home page to download the latest release version of cocos2d-x.
cocos2d-1.0.1-x-0.11.0.zip

I thought you where referring to github, anyway I checked on LayerTest it’s too complicated for me sorry T_T, where in I just want to properly insert a new layer from a basic HelloWorld template and add a sprite from it. Thanks for your help anyway.

Ok I’m getting a bit of progress, I’m getting an error about HelloWorld::init function does not take 0 arguments and it’s point to my LAYER_NODE_FUNC(HelloWorld)

I created a new .h file with

#ifndef __NEO_LEYER_H__
#define __NEO_LEYER_H__

#include "cocos2d.h"

#include "SimpleAudioEngine.h"

class NewLayer : public cocos2d::CCLayer
{
public:

    LAYER_NODE_FUNC(NewLayer);
};
#endif

and on my HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "NeoLayer.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;

class HelloWorld : public cocos2d::CCLayer
{
public:
    NewLayer* test;
    virtual bool init(NewLayer* test);  
    static cocos2d::CCScene* scene();
    virtual void menuCloseCallback(CCObject* pSender);
    LAYER_NODE_FUNC(HelloWorld);
};

#endif

and on my HelloWorldScene.cpp

#include "HelloWorldScene.h"

using namespace cocos2d;

CCScene* HelloWorld::scene()
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::node();
        CC_BREAK_IF(! scene);

        // 'layer' is an autorelease object
        HelloWorld *layer = HelloWorld::node();
        CC_BREAK_IF(! layer);

        // add layer as a child to scene
        scene->addChild(layer);

        NewLayer* newLayer = NewLayer::node(); 
        scene->addChild(newLayer);
        layer->init(newLayer);
    } while (0);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init(NewLayer* testLayer)
{
    CCSprite* test = CCSprite::spriteWithFile("mySprite.png");
    test->setPosition(ccp(100,100));
    testLayer->addChild(test);
return true;
}