2014. 12. 11. 11:16
[D_022] cocos studio 위젯 예제 코드 모음 DATA_OLD/Cocos2d-x 기능성 게임 개발과정2014. 12. 11. 11:16
체크박스, 프로그레스바, 슬라이더, 파티클
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "SimpleAudioEngine.h" #include "cocostudio/CocoStudio.h" #include "ui/CocosGUI.h" USING_NS_CC; using namespace CocosDenshion; using namespace cocostudio; using namespace ui; class HelloWorld : public cocos2d::Layer { public: static cocos2d::Scene* createScene(); virtual bool init(); CREATE_FUNC(HelloWorld); void onTouch(Ref* sender, Widget::TouchEventType type); }; #endif |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include "HelloWorldScene.h" Scene* HelloWorld::createScene() { auto scene = Scene::create(); auto layer = HelloWorld::create(); scene->addChild(layer); return scene; } bool HelloWorld::init() { if ( !Layer::init() ) { return false; } auto node = CSLoader::createNode("MainScene.csb"); node->setTag(0); this->addChild(node); auto check = (CheckBox*)node->getChildByTag(5); check->addTouchEventListener(CC_CALLBACK_2(HelloWorld::onTouch, this)); auto progress = (LoadingBar*)node->getChildByTag(9); progress->setPercent(100); auto slider = (Slider*)node->getChildByTag(10); slider->addTouchEventListener(CC_CALLBACK_2(HelloWorld::onTouch, this)); auto particle = (ParticleSystemQuad*)node->getChildByTag(14); particle->stopSystem(); return true; } void HelloWorld::onTouch(Ref* sender, Widget::TouchEventType type) { auto node = (Node*)this->getChildByTag(0); auto node2 = (Node*)sender; switch (type) { case Widget::TouchEventType::BEGAN: break; case Widget::TouchEventType::MOVED: break; case Widget::TouchEventType::ENDED: { if (node2->getTag() == 5) { auto particle = (ParticleSystemQuad*)node->getChildByTag(14); particle->resetSystem(); auto check = (CheckBox*)node->getChildByTag(5); if (!check->getSelectedState()) { CCLOG("Selected"); } else { CCLOG("Not Selected"); } } else if (node2->getTag() == 10) { auto slider = (Slider*)node->getChildByTag(10); CCLOG("Slider : %d", slider->getPercent()); } } break; } } [출처] 위젯(체크박스, 프로그레스바, 슬라이더, 파티클)|작성자 인자건 |
사운드, 텍스트필드, 패널, 스크롤뷰, 페이지뷰
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 | #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "SimpleAudioEngine.h" #include "cocostudio/CocoStudio.h" #include "ui/CocosGUI.h" USING_NS_CC; using namespace CocosDenshion; using namespace cocostudio; using namespace ui; class HelloWorld : public Layer { public: static Scene* createScene(); virtual bool init(); CREATE_FUNC(HelloWorld); void onTextField(Ref* sender, TextField::EventType type); void onScrollView(Ref* sender, ScrollView::EventType type); }; #endif |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include "HelloWorldScene.h" Scene* HelloWorld::createScene() { auto scene = Scene::create(); auto layer = HelloWorld::create(); scene->addChild(layer); return scene; } bool HelloWorld::init() { if ( !Layer::init() ) { return false; } auto node = CSLoader::createNode("MainScene.csb"); node->setTag(0); this->addChild(node); auto audio = (ComAudio*)node->getChildByTag(12)->getComponent("Audio_3"); audio->playBackgroundMusic(); auto textfield = (TextField*)node->getChildByTag(13); textfield->addEventListener(CC_CALLBACK_2(HelloWorld::onTextField, this)); auto panel = (Layout*)node->getChildByTag(14); panel->setColor(Color3B::RED); auto scroll = (ScrollView*)node->getChildByTag(16); scroll->addEventListener(CC_CALLBACK_2(HelloWorld::onScrollView, this)); return true; } void HelloWorld::onTextField(Ref* sender, TextField::EventType type) { auto textfield = (TextField*)sender; switch (type) { case TextField::EventType::ATTACH_WITH_IME: CCLOG("ATTACH_WITH_IME"); break; case TextField::EventType::DETACH_WITH_IME: { std::string text = textfield->getString(); CCLOG("DETACH_WITH_IME : %s", text.c_str()); } break; case TextField::EventType::INSERT_TEXT: CCLOG("INSERT_TEXT"); break; case TextField::EventType::DELETE_BACKWARD: CCLOG("DELETE_BACKWARD"); break; } } void HelloWorld::onScrollView(Ref* sender, ScrollView::EventType type) { switch (type) { case ScrollView::EventType::SCROLL_TO_TOP: CCLOG("SCROLL_TO_TOP"); break; case ScrollView::EventType::SCROLL_TO_BOTTOM: CCLOG("SCROLL_TO_BOTTOM"); break; case ScrollView::EventType::SCROLLING: CCLOG("SCROLLING"); break; case ScrollView::EventType::BOUNCE_TOP: CCLOG("BOUNCE_TOP"); break; case ScrollView::EventType::BOUNCE_BOTTOM: CCLOG("BOUNCE_BOTTOM"); break; } } [출처] 위젯(사운드, 텍스트필드, 패널, 스크롤뷰, 페이지뷰)|작성자 인자건 |
'DATA_OLD > Cocos2d-x 기능성 게임 개발과정' 카테고리의 다른 글
[D_023] cocos 3.2 에서 3.3rc 프로젝트 버전 변경하기 (0) | 2014.12.16 |
---|---|
[D_023] cocos studio의 장점 (0) | 2014.12.12 |
[D_021] cocos studio 연동 - 노드 로딩 및 오브젝트 조작 등 (0) | 2014.12.10 |
[D_020] Cocos Studio - 기본 세팅, 예제 (0) | 2014.12.09 |
[D_019] 멀티터치 예제 (0) | 2014.12.08 |