Skip to content

Instantly share code, notes, and snippets.

@Kogarasi
Created February 12, 2014 07:46
Show Gist options
  • Save Kogarasi/8951507 to your computer and use it in GitHub Desktop.
Save Kogarasi/8951507 to your computer and use it in GitHub Desktop.
Scene Class for Cocos2dx v3
#include "cocos2d.h"
template <typename T>
class BaseScene : public cocos2d::Layer {
public:
static cocos2d::Scene* createScene(){
auto scene = cocos2d::Scene::create();
auto layer = T::create();
scene->addChild( layer );
return scene;
}
static T* create(){
auto scene = new T();
if( scene && scene->init() ){
scene->autorelease();
return scene;
} else {
delete scene;
return nullptr;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment