Setting
Cocos Studio 2.0.5
cocos2d-x 3.3버전 이상부터 적용 가능
1) 프로젝트 생성
Cocos Studio 프로젝트 생성시, Generate Cocos2d-x Project 체크하여 cocos프로젝트 생성 가능
2) 리소스 추가
리소스 추가는 프로젝트 화면 좌측 하단에 있는 Resources에서 추가한다.
마우스 우클릭 후 Import resources를 선택하여 추가하며, 이때 해당 프로젝트 내의 Resources 폴더를 추가하면 에러가 발생하기 때문에 필히 다른 이름의 폴더에 저장하여 추가하도록 한다.
이렇게 추가한 리소스들은 프로젝트 폴더 내에 cocosstudio에 복사됨.
파일 확장자별 설명
.ccs : 프로젝트 파일
.ccd : 작업 파일. 작업 기록이 남는 듯?
.ccb : 실행파일(binary file). publish하면 res폴더 내에 생기게 됨
이 res폴더 내에 생긴 파일을 프로젝트 폴더 내의 Resources 폴더 내에 옮겨줌.
->VS에서 Cocos Studio를 import한 뒤, 이 파일들을 가지고 노드 형식으로 로드시켜 사용할수있다.
기본 예제
cocos studio에서 가장 기본인 MainScene을 간단히 만든 뒤, 저장하고 publish한다.
그러면 프로젝트 폴더 내에 res폴더가 생기는데, 여기에 생긴 파일을 모두 resources폴더로 복사.
HelloWorldScene.h
Colored By Color Scripter™
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "cocostudio\CocoStudio.h" using namespace cocostudio; class HelloWorld : public cocos2d::Layer { public: // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d::Scene* createScene(); virtual bool init(); CREATE_FUNC(HelloWorld); }; #endif // __HELLOWORLD_SCENE_H__ |
HelloWorldScene.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include "HelloWorldScene.h" USING_NS_CC; Scene* HelloWorld::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } //CocosLoader로 node를 불러옴 auto node = CSLoader::createNode("MainScene.csb"); this->addChild(node); return true; } |
- 버튼 추가 및 콜백 등록 / 태그로 불러와 수정하기 등 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "cocostudio\CocoStudio.h" #include "ui\CocosGUI.h" #include "ui\UIWidget.h" //버튼 사용을 위한 CocosGUI.h //위젯 사용을 위한 Widget.h. USING_NS_CC; //cocos studio를 위한 ns 추가 using namespace cocostudio; using namespace ui; class HelloWorld : public cocos2d::Layer { public: // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d::Scene* createScene(); virtual bool init(); CREATE_FUNC(HelloWorld); void ButtonTouch(Ref* sender, Widget::TouchEventType type); }; #endif // __HELLOWORLD_SCENE_H__ |
Colored By Color Scripter™
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include "HelloWorldScene.h" USING_NS_CC; Scene* HelloWorld::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } //CocosLoader로 node를 불러옴 auto node = CSLoader::createNode("MainScene.csb"); this->addChild(node); auto label = (Label*)node->getChildByTag(4); //label->setString("What the FuXX"); //setString은 안된다. 왠지는 모르겠다. label->setScale(2); //cocos studio에서 추가한 버튼 불러오기 //버튼 클릭시 동작할 메소드 추가 auto button = (Button*)node->getChildByTag(3); button->addTouchEventListener(CC_CALLBACK_2(HelloWorld::ButtonTouch, this)); return true; } void HelloWorld::ButtonTouch(Ref* sender, Widget::TouchEventType type) { CCLOG("button touch"); } |