- 2022.03.28 Monday
- スポンサーサイト
-
一定期間更新がないため広告を表示しています
- | スポンサードリンク | - | | - | - | pookmark |
- 2014.05.20 Tuesday
- cocos2d-x-3.0rc0 ,c++ ,cpp でcocosbuilderのccbiアニメーションファイルをロードする。
-
cocos2d-x-3.0rc0 ,c++ ,cpp でcocosbuilderのccbiアニメーションファイルをロードするよ。
#include "HelloWorldScene.h" #include "cocos-ext.h" #include "cocos/editor-support/cocosbuilder/CCNodeLoaderLibrary.h" #include "cocos/editor-support/cocosbuilder/CCBReader.h" #include "cocos/editor-support/cocosbuilder/CCNodeLoader.h" #include "cocos/editor-support/cocosbuilder/CCLayerLoader.h" #include "cocos/editor-support/cocosbuilder/CCSpriteLoader.h" #include "PrologueSceneLoader.h" using namespace cocosbuilder; using namespace cocos2d::extension; 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; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = LabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen label->setPosition(Point(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1); // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // CocosBuilderのファイルを読み込みゲーム画面を生成する cocosbuilder::NodeLoaderLibrary* nodeLoaderLibrary = cocosbuilder::NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); nodeLoaderLibrary->registerNodeLoader("CCNode", cocosbuilder::NodeLoader::loader()); CCBReader* ccbReader = new cocosbuilder::CCBReader(NodeLoaderLibrary::getInstance()); //http://gin0606.hatenablog.com/entry/2013/12/27/163357 //setCCBRootPathでリソースをダウンロード&保存したパスを指定すると、 //ccbiの中で使ってる画像などのファイルは、そこから探してくれるらしい。 ccbReader->setCCBRootPath("/Users/noboruotsuka/Desktop/cocosproject/rc0/study003/study003/Resources/"); Node* node = ccbReader->readNodeGraphFromFile("mytown_high_space.ccbi"); // node->setPosition( Point(500, 300) ); this->addChild(node); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// return true; } void HelloWorld::menuCloseCallback(Ref* pSender) { Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif }
でいいみたい。 - | whaison | cocos2d-x | 21:00 | comments(0) | - | pookmark |