Creating a Scene

It is very easy to create a Scene

auto myScene = Scene::create();

Remember the Scene Graph?

In Chapter 2 of this guide we learned about a scene graph and how it affects the drawing of our game. The important thing to remember is that this defines the drawing order of the GUI elements. Also remember z-order!

A Simple Scene

Lets's build a simple Scene. Remember that Cocos2d-x uses a right handed coordinate system. This means that our 0,0 coordinate is at the bottom left corner of the screen/display. When you start positioning your game elements this is where you should start your calculations from. Let's create a simple Scene and add a few elements to it:

auto dirs = Director::getInstance();
Size visibleSize = dirs->getVisibleSize();

auto myScene = Scene::create();

auto label1 = Label::createWithTTF("My Game", "Marker Felt.ttf", 36);
label1->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));


auto sprite1 = Sprite::create("mysprite.png");
sprite1->setPosition(Vec2(100, 100));


When we run this code we shall see a simple Scene that contains a Label and a Sprite. It doesn't do much but it's a start.

results matching ""

    No results matching ""