Give me more information about layers - please

I am confused about layers. so i don’t know whether i am using them correctly or not.

var game = cc.scene.extend({
    onEnter: function() {
        //here we create a layer for the game.
        var layer = gameLayer();
    }
});

var gameLayer = cc.Layer.extend({ 

});

There are the default coding we get during the game creation.
I want to have

Background Layer
Menu Layer
Game Layer

Can i have these layers? Or all should be in one single layer?
Now i can have more layers,

var game = cc.scene.extend({
    onEnter: function() {
        //here we create a layer for the game.
        var layer = gameLayer();
       //Background Layer = new BackgroundLayer();
      //Do i need to create the additional layers inside the scene? or inside the main gameLayer?
    }
});

Please give me simple example to understand the process clearly.
Thanks a lot.

Hello @agriz welcome to the community and forums,

To get a generalized idea about how engine works/ features available, and to get familiar with cocos ecosystem head over to this link
http://www.cocos2d-x.org/docs/index.html#welcome-to-the-cocos-docs

@SonarSystems has some good collection of video tuts which should get you started in no time. They can be found here http://www.sonarlearning.co.uk/search.php?searchQuery=cocos2d-x

[quote=“agriz, post:1, topic:26885”]
Please give me simple example to understand the process clearly.
[/quote] Good article to understand layers in your game http://www.cocos2d-x.org/wiki/Layer

[quote=“agriz, post:1, topic:26885”]
I want to have

Background Layer
Menu Layer
Game Layer
[/quote]This will surely help, its closely match your requirement. http://www.cocos2d-x.org/wiki/How_To_Create_A_HUD

Another article which shows how to use Layers to add some effects between different game layers.
http://www.cocos2d-x.org/wiki/User_Tutorial-Create_a_new_scene_or_layer_transition

Although most of these articles follow c++, but concept remains the same. Hope this helps, Tell us if you need any other assistance in getting started.

Happy gaming :smile:

2 Likes

A lot of thanks for your great help!

Sir,

http://www.cocos2d-x.org/wiki/How_To_Create_A_HUD
Where can i find the javascript version for this tutorial.

Thanks again

I am afraid there is no JavaScript article(AFAIK) of given link. You have to understand the concept from above articles and code a version of same. I only programmer with c++ so i can’t be of much help :frowning: may be @slackmoehrle could help you regarding JS version.

Thanks

I wrote this Wiki article a long time ago when I first started working on this team.

I am not sure. I don’t know a lot of JavaScript. but perhaps we could ask some community members to help translate.

I am seeing that most people are using c++
I am thinking to learn c++.

MessageHUD* _hud = MessageHUD::createLayer("The Enemy is approaching!");
this->addChild(_hud, 2);

Director is used to create a scene and scene is creating layers.
Where can i use the above code to create layers? (inside the scene class?)

Is it good if i create a layer inside another layer class?

I think that you should do this where it makes sense in your game.

Here is what I do:

  1. I have a GameObject class that does not sub-class anything.
  2. As member variables I have a Scene and whatever Layer objects I need. (in the .h/.hpp)
  3. I instantiate the Scene and Layer objects as I need them inside the .cpp. Usually not in the class constructor, but I usually have an init() function, etc.