当前位置:网站首页>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
边栏推荐
猜你喜欢
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Tensorflow2.x下如何运行1.x的代码
【C语言】指针进阶---指针你真的学懂了吗?
软件缺陷静态分析 CodeSonar 5.2 新版发布
Mongodb learn from simple to deep
Ubuntu安装mysql8遇到的问题以及详细安装过程
Klocwork 代码静态分析工具
ISO 26262 - 基于需求测试以外的考虑因素
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
神兵利器——敏感文件发现工具
随机推荐
数值法求解最优控制问题(〇)——定义
Update iteration summary of target detection based on deep learning (continuous update ing)
Nebula importer data import practice
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
如何满足医疗设备对安全性和保密性的双重需求?
Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
使用高斯Redis实现二级索引
FTP steps for downloading files from Huawei CE switches
智能软件分析平台Embold
万字总结数据存储,三大知识点
201215-03-19—cocos2dx内存管理–具体解释「建议收藏」
Postgresql数据库character varying和character的区别说明
H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
Spark judges that DF is empty
凌云出海记 | 赛盒&华为云:共助跨境电商行业可持续发展
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
Ubuntu安装mysql8遇到的问题以及详细安装过程
CodeSonar网络研讨会