【CocoStudio游戏开发之三】使用Cocostudio UI编辑器篇

cocos2d-x版本,2.2


cocostudio版本:1.0.2.0


使用cocos2d-x 2.1.3没有成功,cocos2d-x 2.2版本内嵌cocostdio了,所以用2.2


使用cocostudio新建了一个项目,名字“Ma”,里面有两个控件,一个Button,名字“Button”。一个TextView,名字“text”


然后把导出的cocostudio项目添加到vc项目的resource中,然后是代码.h




#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "cocos-ext.h"
USING_NS_CC_EXT;
class HelloWorld : public cocos2d::CCLayer
{
public:
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    // there's no 'id' in cpp, so we recommand to return the exactly class pointer
    static cocos2d::CCScene* scene();
    
    // a selector callback
    void menuCloseCallback(CCObject* pSender);
    void touchEvent(CCObject *pSender, TouchEventType type);
    void countrytouch(CCObject*pSender,TouchEventType type);
    // implement the "static node()" method manually
    UILabel*mText;
    UILabel*mCountryLabel;
    CREATE_FUNC(HelloWorld);
};

#endif  // __HELLOWORLD_SCENE_H__

cpp

#include "HelloWorldScene.h"

using namespace cocos2d;

CCScene* HelloWorld::scene()
{
    CCScene * scene = NULL;
    do 
    {
        scene = CCScene::create();
        CC_BREAK_IF(! scene);
        HelloWorld *layer = HelloWorld::create();
        CC_BREAK_IF(! layer);
        scene->addChild(layer);
    } while (0);
    return scene;
}
bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        CC_BREAK_IF(! CCLayer::init());
        //创建一个画布
        UILayer* ul =UILayer::create();
        //把画布添加到场景中
        this->addChild(ul);
        //创建一个文本框
        mText=UILabel::create();
        mText->setText("text");
        mText->setFontName("");
        mText->setFontSize(32);
        mText->setAnchorPoint(ccp(0.5f, -1));
        mText->setPosition(ccp(100,100));
        ul->addWidget(mText);
        //创建一个Button按钮
        UIButton*playBtn=UIButton::create();
        playBtn->setTouchEnable(true);
        playBtn->setTag(1);
        playBtn->loadTextures("image/btn-play-normal.png","image/btn-play-selected.png","");
        playBtn->addTouchEventListener(this,toucheventselector(HelloWorld::touchEvent));
        playBtn->setPosition(ccp(50,50));
        ul->addWidget(playBtn);

        //调用UI编辑器编辑的按钮
        //把UI编辑的地图添加到画布中
        UIWidget*pUI=CCUIHELPER->createWidgetFromJsonFile("Ma.json");
        ul->addWidget(pUI);
        //获取UI 上Button的的控件
        UIWidget* countryBtn = UIHelper::instance()->seekWidgetByName(pUI,"Button"); 
        //dynamic_cast<UIWidget*>(pUI)
        countryBtn->addTouchEventListener(this,toucheventselector(HelloWorld::touchEvent));
        //获取UI上的Label控件
        mCountryLabel=(UILabel*)(UIHelper::instance()->seekWidgetByName(pUI,"text")); 
        bRet = true;
    } while (0);

    return bRet;
}

void HelloWorld::menuCloseCallback(CCObject* pSender)
{
    CCDirector::sharedDirector()->end();
}
void HelloWorld::touchEvent(CCObject *pSender, TouchEventType type){
    int tag=((UIWidget*)pSender)->getTag();
    switch(tag){
    case 1:
        switch(type){
        case TOUCH_EVENT_BEGAN:
            mText->setText("1");
            break;
        case TOUCH_EVENT_MOVED:
            mText->setText("2");
            break;
        case  TOUCH_EVENT_ENDED:
            mText->setText("3");
            break;
        }
        break;
    case 8:
        switch(type){
        case TOUCH_EVENT_BEGAN:
            mCountryLabel->setText("1");
            break;
        case TOUCH_EVENT_MOVED:
            mCountryLabel->setText("2");
            break;
        case  TOUCH_EVENT_ENDED:
            mCountryLabel->setText("3");
            break;
        }
        break;
    }
};

原文链接: http://www.cnblogs.com/android-qian/p/3425906.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
About CocoStudio is a game development tool kit based on Cocos2d-x. It breaks down tasks in game development into different roles, it includes: UI editor for UI graphic artists, Animation editor for graphic artists, Number cruncher for game data designers, Scene editor for game designers CocoStudio forms a complete game development solution. The UI editor The UI was designed to serve its only purpose: create UI for games. Its simple and intuitive interface allows graphic artists to focus on their expertise, without worrying about other aspects such as programming. Currently the UI editor has 12 different UI elements ready to be used in games, new UI elements will be added with each and every release of CocoStudio, Other key features that the UI editor supports are: Texture packaging - Automatically packs individual texture files into a single large sprite, which further saves memory and improves game performance. Multi-resolution adaption - Automatically adapts to multiple resolution sizes with relative UI positioning. Templating - Reuse the same UI layout across different games, swap out texture resources to give it a new look. The Animation editor The Animation editor was designed to feel like Adobe Flash, which makes graphic artists feel right at home. The Animation editor brings skeletal animation to Cocos2d-x. What advantage does skeletal animation holds against the traditional frame animation? Lower memory consumption - An animation with the traditional frame based solution could use dozens of individual textures, but with skeletal animation, only 1 set of body parts is required to make infinite number of different animations. Smaller file size - due to less number of assets. Animation blending - you can combine animations together to easily make new animation, for example, you could blend attacking animation with walk animation to create "attacking while walking animation". Animation reuse - you can share skeletal animations with another character with the same skeleton setup. Smooth interpolation - traditional frame based animation is very choppy especially in slow motion. Skeletal animation interpolates between 2 sets of key frames, so animation is always played at the same frame rate as the game. However Skeletal animation cannot replace the traditional frame based animation, for example, it cannot make isometric character, it cannot make explosion, that is why we did not forget frame based animation, we even made it better and simpler. You only have to drag and drop frame sequences to the work space, and the animation editor will automatically creates the frame animation for you. Other highlight of Animation editor includes: WYSIWYG collision box editing - editing collision box in wysiwyg way has never being easier and accurate. Reference point - enables characters to wield swords, mount horses, and attaching other objects easily. Texture packing - Automatically packs individual texture files into a single large sprite, which further saves memory and improves game performance. The Data Cruncher The data Cruncher imports excel tables and converts the data into a format readable by cocos2d-x, which can also be used as a component for the Scene editor. The Scene editor The scene editor pieces all the assets made by the UI editor, Animation editor, and the Data Cruncher into a game scene, it can then simulate the game inside the editor. The scene editor also supports many assets made from third party editors such as particle designer, tiled etc. The scene editor relies on the CocosStudio Framework. CocoStudio Framework CocoStudio Framework is an open source higher level framework on top of Cocos2d-x, it employes entity and component system, it is used to read the data saved from the scene editor. The Scene editor saves data in a MVC like fashion, it includes all entities and events used in the current scene, and exports to corresponding code template for the programmers. A programmer can then write the code in Javascript to bring the game alive. CocoStudio的安装 1.CocoStudio的运行平台是Windows操作系统,推荐使用Windows7操作系统。 2.安装CocoStudio之前,确保电脑中安装了.Net 4.0 Framework 3.安装目录尽量不要在C盘的Program Files文件夹下,可能会导致启动器无法启动编辑器。当然,通过“以管理员身份运行”的方式也可以打开软件 4.在Xp和Windows8的操作系统下,可能会出现的闪屏或无法运行的问题。这个问题会尽快修复
H-ui.admin是用H-ui前端框架开发的轻量级网站后台模版 采用源生html语言,完全免费,简单灵活,兼容性好 让您快速搭建中小型网站后台 程序员的的福音 \根目录 │ _blank.html 空白页(每次我们都拿空白页去创建,这样比较干净!) │ _footer.html 页脚公共代码片段 │ _header.html 头部公共代码片段 │ _meta.html meta公共代码片段 │ robots.txt 搜索引擎爬虫配置文件 │ login.html 管理员登陆 │ index.html 首页(主框架) │ welcome.html 我的桌面(默认永远打开的页面) │ member-开头的 用户相关 │ artice-开头的 资讯相关 │ picture-开头的 图片相关 │ product-开头的 产品相关 │ page-开头的 页面相关 │ system-开头的 系统相关 │ admin-开头的 管理员相关 │ charts-开头的 统计相关 …… ├─css │ H-ui.reset.css H-ui.reset css │ H-ui.css h-ui CSS │ H-ui.min.css h-ui CSS 压缩版 │ H-ui.login.css H-ui.admin后台登录样式 │ H-ui.admin.css H-ui.admin样式 │ style.css 写你自己的样式 │ ├─images UI相关的图片素材 │ ├─js │ H-ui.js H-ui核心脚本 │ H-ui.admin.js 本站相关的js ├─lib │ jquery jQuery类库(v1.9.1) │ bootstrapSwitch 开关控件 │ Hui-iconfont_v1.0 阿里图标字体库(H-ui定制) │ font-awesome 字体库文件 │ icheck 单选框、复选框控件 │ laypage laypage 翻页插件 │ layer layer弹出层插件 │ laytpl JavaScript模板引擎 │ My97DatePicker 日期插件 │ Validform 表单验证插件 │ zepto zepto库 │ ueditor 百度编辑器 │ Highcharts 图表插件 │ dataTables 表格排序,检索插件 │ WebUploader 百度文件上传组件 │ lightbox2 图片预览组件 │ │ html5.js html5插件,让低版本IE支持html5元素 │ DD_belatedPNG_0.0.8a-min.js 解决IE6png透明 │ swfobject.js Flash插件 │ expressInstall.swf 检查flash插件 │ unslider.min.js Unslider图片滚动效果插件 │ stickUp.min.js 让页面元素"固定"位置 │ respond.min.js 让IE兼容media │ Echo.js 图片延迟加载插件 │ colpick.js 颜色插件 │ handlebars.js js模版引擎 │ waterfall.min.js 瀑布流插件 └─temp 测试数据、图片

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值