【cocos2dx 3.10】简述 cocos studio 的使用

前端之家收集整理的这篇文章主要介绍了【cocos2dx 3.10】简述 cocos studio 的使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.创建场景

略过,自己打开cocos studio自己随便弄就会了。


2.发布项目

菜单->项目->发布与打包-> 发布->发布资源->确定


点“确定”按钮后,资源会发布到“/Resource/res”,这是默认路径,可以自己修改


3.给按钮添加事件

如果你在cocos studio添加了一个按钮,是不是要指定一个点击回调函数代码如下:

  1. #include "cocos2d.h"
  2. #include "ui/CocosGUI.h"
  3.  
  4. USING_NS_CC;
  5. using namespace cocos2d::ui;
  6.  
  7. ui::Button* _testButton = nullptr;
  8.  
  9. //init函数
  10. //按钮
  11. _testButton = static_cast<Button*>(rootNode->getChildByName("start"));
  12. _testButton->addClickEventListener(CC_CALLBACK_1(HelloWorld::testClick,this));


添加输入框和获取内容代码如下:

  1. ui::TextField* _testTextField = nullptr;
  2.  
  3. //输入框
  4. _testTextField = static_cast<TextField*>(rootNode->getChildByName("TextField_1"));
  5.  
  6. CCLOG("%s",_testTextField->getString());



注:

1.cocos studio里面的名称就是节点名称,可以通过getChildByName获取节点

2.逻辑标签就是tag

3.注意父子关系,别到时候说获取不到节点。

猜你在找的Cocos2d-x相关文章