cocos2d-x 3.1 +cocostudio 整合应用2
2014-09-15 10:00
211 查看
</pre>1.<span style="font-family:宋体">动画操作</span><span style="letter-spacing:0pt; font-size:9pt; font-family:Arial"></span><p></p><p class="p15" style="margin-bottom:3pt; margin-top:3pt; padding:0pt"><span style="letter-spacing:0pt; font-size:10pt; font-family:Arial">注意<span style="font-family:Arial">cocostudio</span><span style="font-family:宋体">动画、场景的操作的</span><span style="font-family:Arial">api---</span></span><span style="color:rgb(255,0,0); letter-spacing:0pt; font-size:10pt; font-family:Arial">D:\cocos2d\cocos2d-x-3.1.1\tests\cpp-tests\Classes\ExtensionsTest<span style="font-family:宋体">。</span></span><span style="letter-spacing:0pt; font-size:10pt; font-family:Arial">而<span style="font-family:Arial">ui</span><span style="font-family:宋体">的操作的</span><span style="font-family:Arial">api</span><span style="font-family:宋体">是</span><span style="font-family:Arial">D:\cocos2d\cocos2d-x-3.1.1\tests\cpp-tests\Classes\UITest</span><span style="font-family:宋体">。所以要格外注意。</span></span><span style="letter-spacing:0pt; font-size:9pt; font-family:Arial"></span></p><p class="p15" style="margin-bottom:3pt; margin-top:3pt; padding:0pt"></p><p class="p15" style="margin-bottom:3pt; margin-top:3pt; padding:0pt">取得动画的代码如下:</p><p class="p15" style="margin-bottom:3pt; margin-top:3pt; padding:0pt"><span style="letter-spacing:0pt; font-size:10pt; font-family:Arial"><span style="font-family:宋体"></span></span></p><pre name="code" class="cpp"> ArmatureDataManager::getInstance()->addArmatureFileInfo("DemoPlayer/DemoPlayer.ExportJson"); Armature* armature = Armature::create("DemoPlayer"); armature->setTag(AM_MYANIMATION); armature->getAnimation()->playWithIndex(0); armature->setPosition(Point(origin.x + visibleSize.width/2 , origin.y + visibleSize.height/2)); this->addChild(armature);在 事件中播放动画:
void HelloWorld::onMoveRight(cocos2d::CCObject *pSender, TouchEventType type) { auto armature = (Armature*)getChildByTag(AM_MYANIMATION); if(type == TOUCH_EVENT_BEGAN) { armature->getAnimation()->play("walk"); } if (type == TOUCH_EVENT_ENDED) { armature->getAnimation()->play("stand"); } }贴上demo代码:http://download.csdn.net/detail/qqq644755786/7917397
2场景操作:
场景操作是为了整合UI界面与动画元素,
就可以导入以前做的动画或者Ui编辑器了。这个文件夹是相关例子:D:\cocos2d\cocos2d-x-3.1.1\tests\cpp-tests\Classes\ExtensionsTest\CocoStudioSceneTest
调用的代码如下:
//添加cocostudio的文件--场景编辑器 auto node = SceneReader::getInstance()->createNodeWithSceneFile("publish/Scene01.json"); if(node) { addChild(node); } //场景编辑器寻找ui编辑器 auto child = node->getChildByTag(10005); auto reader = (ComRender*)child->getComponent("GUIComponent"); Widget *uiLayer=static_cast<cocos2d::ui::Widget*>(reader->getNode()); //Button btn_start = dynamic_cast<Button*>(uiLayer->getChildByTag(UI_Btn_Start)); btn_start->addTouchEventListener(this,toucheventselector(HelloWorld::touchButton)); //checkBox show_view= dynamic_cast<CheckBox*>(uiLayer->getChildByTag(UI_CheckBox)); show_view->setSelectedState(true);//设置初始状态 show_view->addEventListener(CC_CALLBACK_2(HelloWorld::selectedEvent, this)); //Label--是Text _displayValueLabel=dynamic_cast<Text*>(uiLayer->getChildByTag(UI_Label)); int m=50; _displayValueLabel->setString(CCString::createWithFormat("percent %d", m)->getCString()); //imageView --用name方式 imgView = static_cast<ImageView*>(Helper::seekWidgetByName(uiLayer,"Image_3")); //Slider slider = dynamic_cast<Slider*>(uiLayer->getChildByTag(UI_Slide)); slider->setPercent(35); slider->addEventListener(CC_CALLBACK_2(HelloWorld::sliderEvent, this)); //数字标签TextAtlas num_ValueLabel=dynamic_cast<TextAtlas*>(uiLayer->getChildByTag(UI_NUmLabel)); num_ValueLabel->setString(CCString::createWithFormat("percent %d",0)->getCString()); //loadingbar loadbar=dynamic_cast<LoadingBar*>(uiLayer->getChildByTag(UI_LoadingBar)); loadbar->setPercent(25); //textField文本框 text_name=dynamic_cast<TextField*>(uiLayer->getChildByTag(UI_TextField_name)); text_password=dynamic_cast<TextField*>(uiLayer->getChildByTag(UI_TextField_password)); text_name->addEventListener(CC_CALLBACK_2(HelloWorld::textFieldEvent, this)); text_password->addEventListener(CC_CALLBACK_2(HelloWorld::textFieldEvent, this));
使用场景编辑器调用动画
//场景编辑器寻找动画编辑器 ComRender *render = static_cast<ComRender*>(node->getChildByTag(10003)->getComponent("CCArmature")); armature = static_cast<Armature*>(render->getNode()); //armature->setTag(AM_MYANIMATION); armature->setPosition(Point(origin.x + visibleSize.width/2 ,origin.y + visibleSize.height/2)); btn_left = dynamic_cast<Button*>(uiLayer->getChildByTag(UI_Btn_Left)); btn_left->addTouchEventListener(this,toucheventselector(HelloWorld::onMoveLeft));
附上demo地址:还是要收1积分希望大家支持http://download.csdn.net/detail/qqq644755786/7917407
谢谢入门级别的cocostudio就这些了
相关文章推荐
- cocos2d-x 3.1 +cocostudio 整合应用
- cocos2d-lua整合到ios工程,即在ios原生应用中可以直接玩cocoslua开发的游戏
- plist在cocos2d-3.1中的应用
- CocoStudio在Cocos2d-x Lua项目中的应用--加载动画 管理提醒: 本帖被 young40 执行压帖操作(2014-03-28)
- CocoStudio在Cocos2d-x Lua项目中的应用--加载动画
- 如何在SharePoint Server中整合其他应用系统?
- 整合Java与XML的新应用(zz)
- 如何在SharePoint Server中整合其他应用系统?
- Windows XP权限整合应用全解
- Windows XP权限整合应用全解
- Spring与其他工具、框架整合应用
- [转]应用整合中SSO的技术实现
- 企业应用集成专题----实现应用整合的七层架构方案
- 应用整合中SSO的技术实现
- 关于TOMCAT APACHE整合后的servlet应用!
- 应用整合中SSO的技术实现
- 在ROR应用中整合FCKEditor
- 谈Apache + IIS + Tomcat5.5整合应用
- 整合Java与XML的新应用
- Hibernate3与spring的整合应用