当前位置:网站首页>Cocos2d-x game archive [easy to understand]
Cocos2d-x game archive [easy to understand]
2022-07-07 20:45:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
The game archive function can save the data in the game . Let players continue the game . Single game is more important . and CCUserDefault It can be used as a lightweight database , Used to store data , Support data types bool,int, float, double, string.
Store the data
CCUserDefault::sharedUserDefault()->setStringForKey("string", "value1"); // Parameter order : key . The corresponding value
CCUserDefault::sharedUserDefault()->setIntegerForKey("integer", 10);
CCUserDefault::sharedUserDefault()->setFloatForKey("float", 2.3f);
CCUserDefault::sharedUserDefault()->setDoubleForKey("double", 2.4);
CCUserDefault::sharedUserDefault()->setBoolForKey("bool", true);
Get the above data output
string str = CCUserDefault::sharedUserDefault()->getStringForKey("string");// Parameters : Return key value according to the passed in key
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");
Change data
CCUserDefault::sharedUserDefault()->setStringForKey("string", "test"); // changes string data
CCUserDefault::sharedUserDefault()->setFloatForKey("float", 3.1413); // changes float data
string str1 = CCUserDefault::sharedUserDefault()->getStringForKey("string");
CCLOG("str1: %s", str1.c_str());
float f2 =CCUserDefault::sharedUserDefault()->getFloatForKey("float");
CCLOG("f2: %f", f2);
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116383.html Link to the original text :https://javaforall.cn
边栏推荐
- sqlHelper的增删改查
- Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
- 使用高斯Redis实现二级索引
- 【论文阅读】MAPS: Multi-agent Reinforcement Learning-based Portfolio Management System
- Deep learning model compression and acceleration technology (VII): mixed mode
- ISO 26262 - 基于需求测试以外的考虑因素
- 阿洛的烦恼
- object-c编程tips-timer「建议收藏」
- 微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
- 静态测试工具
猜你喜欢
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
How does codesonar help UAVs find software defects?
软件缺陷静态分析 CodeSonar 5.2 新版发布
测量楼的高度
Klocwork 代码静态分析工具
OneSpin | 解决IC设计中的硬件木马和安全信任问题
Apifox interface integrated management new artifact
H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法
Ubuntu安装mysql8遇到的问题以及详细安装过程
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
随机推荐
机械臂速成小指南(十一):坐标系的标准命名
Intelligent software analysis platform embold
使用 BR 恢复 Azure Blob Storage 上的备份数据
How to choose fund products? What fund is suitable to buy in July 2022?
Small guide for rapid formation of manipulator (12): inverse kinematics analysis
sqlHelper的增删改查
object-c编程tips-timer「建议收藏」
CodeSonar网络研讨会
How does codesonar help UAVs find software defects?
理财产品要怎么选?新手还什么都不懂
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
HDU4876ZCC loves cards(多校题)
华为CE交换机下载文件FTP步骤
Mongodb learn from simple to deep
Implement secondary index with Gaussian redis
上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法
Implement secondary index with Gaussian redis
H3C s7000/s7500e/10500 series post stack BFD detection configuration method
死锁的产生条件和预防处理[通俗易懂]
SQL注入报错注入函数图文详解