Cocos2d-x 3.x开发——导入Cocostudio资源
转自:http://segmentfault.com/blog/codecabin/1190000000593010
目前正在和实训的小组成员一起做一款手机2D游戏,我们采用了Cocos2d-x进行开发。之前虽然早有耳闻,这次却是第一次认真地学习和使用Cocos2d-x。最开始的几天就是在不停的看文档和爬坑。其中一个坑就是Cocostudio这货。官网的文档滞后而且不够详细,为了弄清楚,借鉴了很多博客,也阅读了示例代码。 Node *pNode = GUIReader::getInstance()->widgetFromJsonFile("test.ExportJson");
this->addChild(pNode);
下面就可以用 Button *button = (Button*)(ui::Helper::seekWidgetByName(pNode,"button"));
顺便附上绑定事件监听的代码,使看到的人免去寻找之苦。 button->addTouchEventListener(CC_CALLBACK_2(MainScene::touchEvent,this));
void SingleMenuScene::selectEvent(Ref *pSender,Widget::TouchEventType type)
{
switch(type)
{
case Widget::TouchEventType::ENDED:
GameSetting::Map map = GameSetting::Map::DEFAULT;
if(pSender == defaultBtn)
{
map = GameSetting::Map::DEFAULT;
}
else if(pSender == snowBtn) {
map = GameSetting::Map::SNOW;
}
Scene *game = BattleScene::createScene(map);
TransitionScene *transition = TransitionFade::create(0.5,game);
Director::getInstance()->replaceScene(transition);
}
}
导入动画编辑器的动画的代码如下: CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Animation0.png",152)">"Animation0.plist",152)">"Animation.ExportJson");
CCArmature *armature = CCArmature::create("Animation");
armature->getAnimation()->playByIndex(0);
armature->setScale(0.5f);
armature->setPosition(ccp(visibleSize.width * 0.5));
this->addChild(armature);
导入场景编辑器的场景的代码如下: Node* pNode = SceneReader::getInstance()->createNodeWithSceneFile("scene.ExportJson");
这个读出的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |