当前位置:网站首页>Cocos2d-x 游戏存档[通俗易懂]
Cocos2d-x 游戏存档[通俗易懂]
2022-07-07 20:03:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
游戏存档功能能够保存游戏中数据。让玩家游戏能够延续。 单机游戏更为重要。而CCUserDefault能够作轻量级数据库使用,用来存储数据,支持数据类型bool,int, float, double, string.
存储数据
CCUserDefault::sharedUserDefault()->setStringForKey("string", "value1"); //參数顺序:键。相应的值
CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 10);
CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.3f);
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.4);
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", true);获取上面数据输出
string str = CCUserDefault::sharedUserDefault()->getStringForKey("string");//參数:依据传入的键返回键值
CCLOG("str: %s", str.c_str());
int i = CCUserDefault::sharedUserDefault()->getIntegerForKey("integer");
CCLOG("i: %d", i);
float f = CCUserDefault::sharedUserDefault()->getFloatForKey("float");
CCLOG("f: %f", f);
double d = CCUserDefault::sharedUserDefault()->getDoubleForKey("double");
CCLOG("d: %f", d);
bool b = CCUserDefault::sharedUserDefault()->getBoolForKey("bool");
if (b)
CCLOG("bool is true");
else
CCLOG("bool is false");改动数据
CCUserDefault::sharedUserDefault()->setStringForKey("string", "test"); //改动string数据
CCUserDefault::sharedUserDefault()->setFloatForKey("float", 3.1413); //改动float数据
string str1 = CCUserDefault::sharedUserDefault()->getStringForKey("string");
CCLOG("str1: %s", str1.c_str());
float f2 =CCUserDefault::sharedUserDefault()->getFloatForKey("float");
CCLOG("f2: %f", f2);发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116383.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢

Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围

Static analysis of software defects codesonar 5.2 release

CodeSonar如何帮助无人机查找软件缺陷?

OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
Mysql子查询关键字的使用方式(exists)

最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化

Apifox interface integrated management new artifact

Jenkins 用户权限管理

上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法

ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
随机推荐
Update iteration summary of target detection based on deep learning (continuous update ing)
FTP steps for downloading files from Huawei CE switches
开发一个小程序商城需要多少钱?
[function recursion] do you know all five classic examples of simple recursion?
实战:sqlserver 2008 扩展事件-XML转换为标准的table格式[通俗易懂]
使用高斯Redis实现二级索引
字符串中数据排序
解决使用uni-app MediaError MediaError ErrorCode -5
Is it safe to open a stock account at present? Can I open an account online directly.
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
JNI 初级接触
OneSpin | 解决IC设计中的硬件木马和安全信任问题
让这个CRMEB单商户微信商城系统火起来,太好用了!
阿洛的烦恼
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
Useful win11 tips
Ubuntu安装mysql8遇到的问题以及详细安装过程
Codesonar enhances software reliability through innovative static analysis
Numerical method for solving optimal control problem (0) -- Definition
Write a jump table