Appendix B - Android with Terminal Installation and Setup
Appendix C - Android with Eclipse Installation and Setup
Appendix D - iOS Installation and Setup
Appendix E - Mac OSX Installation and Setup
Appendix F - Linux Installation and Setup
Appendix G - Win32 Installation and Setup
Appendix H - WP8 Installation and Setup
Appendix I - Creating a New Example Project
This introduction requires a working Cocos2d-x setup to complete. Please ensure that you have gone through the appropriate installation steps for your platform. Please review the Appendix for Installation Guides
.
Follow Appendix H for 'Creating A New Example Project'.
Navigate to your new project and open it. This is dependepent upon the platform that you are running on. Please refer to the appropriate Appendix for your installation.
Let's Begin!
Everything you need to get started! Platform specific source files, Cocos2d-x and the Resources used in the 'Hello World' sample.
'Hello World' has a default Scene, but lets ignore it and create our own.
File -> New -> File
or Command-N
and lets create a C++ class.
Select Next
and let's call our new Scene MainScene.cpp
.
Select Create
.
Select the MainScene.h
and paste in the following code:
#ifndef __MAINSCENE_H__
#define __MAINSCENE_H__
#include <iostream>
#include "cocos2d.h"
class MainScene
{
public:
MainScene();
~MainScene();
static cocos2d::Scene* createScene();
virtual cocos2d::Scene* getScene() { return scene; };
private:
cocos2d::Scene* scene;
cocos2d::LayerColor* layer;
};
#endif // __MAINSCENE_H__
Select the MainScene.cpp
and paste in the following code:
//
// MainScene.cpp
//
#include "MainScene.h"
MainScene::MainScene()
{
// get the display size of the device we are using
cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
cocos2d::Vec2 origin = cocos2d::Director::getInstance()->getVisibleOrigin();
// scene
scene = cocos2d::Scene::create();
scene->setContentSize(visibleSize);
// layer
layer = cocos2d::LayerColor::create(cocos2d::Color4B(120, 50, 50, 120), visibleSize.width, visibleSize.height);
// finally add the built up Layer to the Scene.
scene->addChild(layer, 0);
}
MainScene::~MainScene() {}
cocos2d::Scene* MainScene::createScene()
{
MainScene m;
return m.getScene();
}
And finally, in AppDelegate.cpp
, replace:
auto scene = HelloWorld::createScene();
with:
cocos2d::Scene* scene = MainScene::createScene();
That's it! But the Scene is empty. Lets add some content.
Lets start to make a simple game!
First, download <> and toss the contents in the Resources
directory for your project. Add them to your IDE.
Second, past in the following code: