HomeScene에 파라미터가 포함된 HomeLayer를 추가하는 방법
HomeScene.h
HomeScene.cpp
HomeLayer.h
HomeLayer.cpp
HomeScene.h
#ifndef __Fortune__HomeScene__ #define __Fortune__HomeScene__ #include "cocos2d.h" class HomeScene:public cocos2d::Scene { public: static cocos2d::Scene* createScene(); }; #endif
HomeScene.cpp
#include "HomeScene.h" #include "HomeLayer.h" cocos2d::Scene* HomeScene::createScene() { auto scene = cocos2d::Scene::create(); auto layer = HomeLayer::createWithScenetype(2); scene->addChild(layer); return scene; }
HomeLayer.h
#include "cocos2d.h" class HomeLayer:public cocos2d::Layer { public: static cocos2d::Layer* createWithScenetype(int st); bool init(int st); private: int _type; };
HomeLayer.cpp
#include "HomeLayer.h" Layer* HomeLayer::createWithScenetype(int st) { auto layer = new HomeLayer(); if (layer && layer->init(st)) { layer->autorelease(); return layer; } return NULL; } bool HomeLayer::init(int st) { if (!Layer::init()) { return false; } _type = st; log("scene type : %d", _type); } return true; }
댓글 없음:
댓글 쓰기