CocoStudio基础教程(1)创建UI并载入到程序中

时间:2023-03-09 19:09:47
CocoStudio基础教程(1)创建UI并载入到程序中

1、概述

CocoStudio的使用无疑是cocos2d-x 3.0的重要组成部分,接下来我们用它来创建一组UI,并将其读入到程序中显示出来。先上效果图:

2、导出

在导出之前,最好先创建一个新的工程。运行我们的脚本文件,给新工程起名为:HelloStudio。编译运行,保证它没问题。

回到CocoStudio中,点选 文件 –> 导出项目 。在导出资源的位置,选择“导出使用大图”。同时将目录改为我们项目文件的Resource目录。

4、加载到程序中

bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
} /////////////////////////////////
UILayer* uiLayer = UILayer::create();
auto myLayout = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("testUI.ExportJson")); //alpha0中使用
auto myLayout = cocostudio::GUIReader::shareReader()->widgetFromJsonFile("testUI.ExportJson")); //alpha1中使用
uiLayer->addWidget(myLayout);
this->addChild(uiLayer); return true;
}