1. cocos2d-x 3.1 +cocostudio 环境搭建
http://www.cocoachina.com/bbs/read.php?tid=194668 此文章已经很详细了
配置属性" => "C/C++" => "附加包含目录" 并编辑.
注意:1.1这三个文件要引用的文件夹分别为
D:\cocos2d-x-3.1.1\cocos\editor-support\cocostudio\proj.win32
D:\cocos2d-x-3.1.1\extensions\proj.win32
D:\cocos2d\cocos2d-x-3.1.1\cocos\ui\proj.win32
1.2 添加下面几行.我直接复制过来 大家直接用
$(EngineRoot);$(EngineRoot)cocos;$(EngineRoot)cocos\editor-support\;$(EngineRoot)cocos\editor-support\cocostudio;$(EngineRoot)cocos\audio\include;$(EngineRoot)external;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)extensions;..\Classes;..;%(AdditionalIncludeDirectories)
1.3导入的源程序 一定要加 --特别是ui文件夹下的CocosGui 我找了好半天的
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
using namespace ui;
using namespace cocostudio;
2 入门级别的cocostudio
注意 其实下载的cocos2d-x-3.1.1的文件夹D:\cocos2d\cocos2d-x-3.1.1\tests\cpp-tests\Classes\UITest\CocoStudioGUITest有相关的所有操作
资源文件夹为:D:\cocos2d\cocos2d-x-3.1.1\tests\cpp-tests\Resources
HelloWorld.h:如下
#include "cocos2d.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
USING_NS_CC;
using namespace ui;
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();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
void menuCloseCallback(Object* pSender);
CREATE_FUNC(HelloWorld);
void touchButton(Object* obj,TouchEventType eventType);
void selectedEvent(Ref* pSender,CheckBox::EventType type);
void sliderEvent(Ref *pSender, Slider::EventType type);
void update(float dt);
void textFieldEvent(Ref *pSender, TextField::EventType type);
private:
int _count;
bool m_isRunning;
ui::Button* btn_start,*btn_left,*btn_right;
ui::CheckBox *show_view;
ui::ImageView *imgView;//图片
ui::Slider* slider;
ui::Layout* uiLayer;
ui::Slider* slide;
ui::LoadingBar* loadbar;
ui::ScrollView*ScollView;
ui::Text * _displayValueLabel;
ui::TextAtlas* num_ValueLabel;//数字标签
ui::TextBMFont* bitmLabel;//字体标签
ui::TextField* text_name,*text_password;
};
HelloWorld.cpp部分代码如下
<span style="white-space:pre"> </span>uiLayer= static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("NewUi11_1/NewUi11_1.json"));
addChild(uiLayer);
//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));
_count=0;
this->schedule(schedule_selector(HelloWorld::update));
setTouchEnabled(true);
现在发一下我的demo的地址 : http://download.csdn.net/detail/qqq644755786/7897621
当然我是屌丝所有就收1积分,谢谢大家捧场啊。
3入门级别的cocostudio--关于骨骼动画与场景编辑器的应用(见下篇)