Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Created September 4, 2014 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sag333ar/05ab612e38111a35ae67 to your computer and use it in GitHub Desktop.
Save sag333ar/05ab612e38111a35ae67 to your computer and use it in GitHub Desktop.
Default/File-template for Game-Scene in Cocos2d-x
//------------------------------------Headr File------------------------------------------
//----------------------------------------------------------------------------------------
#ifndef __GAME_SCENE_H__
#define __GAME_SCENE_H__
#include "cocos2d.h"
class GameScene : public cocos2d::LayerColor
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(GameScene);
};
#endif // __GAME_SCENE_H__
//----------------------------------------------------------------------------------------
//------------------------------------Footer File-----------------------------------------
//----------------------------------------------------------------------------------------
#include "GameScene.h"
USING_NS_CC;
Scene* GameScene::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = GameScene::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
bool GameScene::init() {
if ( !LayerColor::initWithColor(Color4B(255.0, 255.0, 255.0, 255.0))) {
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
return true;
}
//----------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment