Cocos2dx 3.1.1 之 数据存储

本文深入探讨了游戏开发领域的关键技术,包括Unity3D和Cocos2dX引擎的应用,以及如何利用AI和音视频技术实现更丰富的交互体验。重点介绍了图像处理、AR特效、语音识别和深度学习在游戏中的应用案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首选项存储:

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

	//存储数据
	UserDefault::getInstance()->setStringForKey("data", "Hello World!");
	//取出并打印数据			//根据key("data")获取数据,如果找不到则输出失败值"can not find!"
	log("%s", UserDefault::getInstance()->getStringForKey("data", "can not find!").c_str());

    return true;
}



读写文件:

写文件:

    auto fu = FileUtils::getInstance();
    FILE *f = fopen(fu->fullPathFromRelativeFile("data.txt", fu->getWritablePath()).c_str(), "w");
    fprintf(f, "Hello World!\n");
    fclose(f);


读文件:

    Data d = fu->getDataFromFile(fu->fullPathFromRelativeFile("data.txt", fu->getWritablePath()));
    
    log("%s",d.getBytes());



读取plist文件

	FileUtils *fu = FileUtils::getInstance();
	ValueMap vm = fu->getValueMapFromFile("data.plist");
	log("%s",vm["name"].asString().c_str());


读取xml文件

#include "tinyxml2.h"

    auto doc = new tinyxml2::XMLDocument();
    doc->Parse(FileUtils::getInstance()->getStringFromFile("data.xml").c_str());
    auto root = doc->RootElement();
    
    for (auto e = root->FirstChildElement(); e; e=e->NextSiblingElement()) {
        
        std::string str;
        
        for (auto attr = e->FirstAttribute(); attr; attr=attr->Next()) {
            str+=attr->Name();
            str+=":";
            str+=attr->Value();
            str+=",";
        }
        
        log("%s",str.c_str());
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值