当前位置:网站首页>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
边栏推荐
- margin 等高布局
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
- Spark 判断DF为空
- Klocwork 代码静态分析工具
- Numerical method for solving optimal control problem (0) -- Definition
- Data sorting in string
- You want to kill a port process, but you can't find it in the service list. You can find this process and kill it through the command line to reduce restarting the computer and find the root cause of
- awk处理JSON处理
- openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
- Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system
猜你喜欢
不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统
如何满足医疗设备对安全性和保密性的双重需求?
机械臂速成小指南(十一):坐标系的标准命名
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
让这个CRMEB单商户微信商城系统火起来,太好用了!
恶魔奶爸 B3 少量泛读,完成两万词汇量+
SQL注入报错注入函数图文详解
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
CodeSonar网络研讨会
Tensorflow2. How to run under x 1 Code of X
随机推荐
How does codesonar help UAVs find software defects?
Codesonar Webinar
使用 BR 备份 TiDB 集群数据到 Azure Blob Storage
Codesonar enhances software reliability through innovative static analysis
寫一下跳錶
Postgresql数据库character varying和character的区别说明
Micro service remote debug, nocalhost + rainbow micro service development second bullet
DataTable数据转换为实体
【网络原理的概念】
写一下跳表
H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法
反诈困境,国有大行如何破局?
阿洛的烦恼
ISO 26262 - 基于需求测试以外的考虑因素
使用枚举实现英文转盲文
SQL注入报错注入函数图文详解
恶魔奶爸 C
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
恶魔奶爸 B2 突破语法,完成正统口语练习
Alibaba cloud award winning experience: how to mount NAS file system through ECS