当前位置:网站首页>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
边栏推荐
- Implement secondary index with Gaussian redis
- 恶魔奶爸 C
- 【C语言】指针进阶---指针你真的学懂了吗?
- Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)
- [concept of network principle]
- Guava multithreading, futurecallback thread calls are uneven
- Alibaba cloud award winning experience: how to mount NAS file system through ECS
- 华为CE交换机下载文件FTP步骤
- Referrer和Referrer-Policy简介
- [award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
猜你喜欢

AADL inspector fault tree safety analysis module

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

ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Klocwork 代码静态分析工具

智能软件分析平台Embold

Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

C language helps you understand pointers from multiple perspectives (1. Character pointers 2. Array pointers and pointer arrays, array parameter passing and pointer parameter passing 3. Function point

使用camunda做工作流设计,驳回操作
Codesonar enhances software reliability through innovative static analysis
随机推荐
Measure the height of the building
npm uninstall和rm直接删除的区别
让这个CRMEB单商户微信商城系统火起来,太好用了!
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
【网络原理的概念】
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
Numerical method for solving optimal control problem (0) -- Definition
恶魔奶爸 A1 语音听力初挑战
Introduction to referer and referer policy
H3C s7000/s7500e/10500 series post stack BFD detection configuration method
Write a jump table
阿里云有奖体验:如何通过ECS挂载NAS文件系统
【函数递归】简单递归的5个经典例子,你都会吗?
Micro service remote debug, nocalhost + rainbow micro service development second bullet
静态测试工具
嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]
OneSpin | 解决IC设计中的硬件木马和安全信任问题
Spark judges that DF is empty
恶魔奶爸 指南帖——简易版