温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Cocos Studio 数据编辑器新手使用教程

发布时间:2020-07-13 23:20:18 来源:网络 阅读:680 作者:huyanruirui 栏目:开发技术

1. 在数据编辑器中导入Excel文件

Cocos Studio 数据编辑器新手使用教程

Cocos Studio 数据编辑器新手使用教程

2. 导出Json文件,选择属性模式

Cocos Studio 数据编辑器新手使用教程

3. 使用文本编辑器查看Json数据

Cocos Studio 数据编辑器新手使用教程Cocos Studio 数据编辑器新手使用教程

4. 在程序中添加Json解析函数

void getJsonFromFile(const char* fileName, rapidjson::Document &jsonDict)
{
    unsigned char *pBytes = NULL; 
    std::string jsonpath; 
    jsonpath = CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName); 
    unsigned long size = 0; 
    pBytes = CCFileUtils::sharedFileUtils()->getFileData(jsonpath.c_str(), "r" , &size); 
    CCData *data = new CCData(pBytes, size); 
    std::string load_str = std::string((const char *)data->getBytes(), data->getSize() ); 
    CC_SAFE_DELETE(data); 
    jsonDict.Parse<0>(load_str.c_str()); 
}

5. 获取Json文件中的数据

rapidjson::Document rapidJsonData; 
getJsonFromFile("data.json", rapidJsonData); 
for(int i = 0; i < 4; i++)
{
    const char* name = DictionaryHelper::shareHelper()->getStringValue_json(rapidJsonData[i], "name");
    int level = DictionaryHelper::shareHelper()->getIntValue_json(rapidJsonData[i], "level");
    int hp = DictionaryHelper::shareHelper()->getIntValue_json(rapidJsonData[i], "hp");
    int attack = DictionaryHelper::shareHelper()->getIntValue_json(rapidJsonData[i], "attack");
    CCLog("%s, %d, %d, %d", name, level, hp, attack);
}

6. 程序运行结果

Cocos Studio 数据编辑器新手使用教程


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI