当前位置:网站首页>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
边栏推荐
- Flask1.1.4 Werkzeug1.0.1 源码分析:路由
- 微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
- Klocwork code static analysis tool
- ISO 26262 - 基于需求测试以外的考虑因素
- Jetty:配置连接器[通俗易懂]
- Introduction to referer and referer policy
- 恶魔奶爸 A0 英文零基础的自我提升路
- Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
- 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
- npm uninstall和rm直接删除的区别
猜你喜欢

程序猿赚的那点钱算个P啊!

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

Implement secondary index with Gaussian redis

神兵利器——敏感文件发现工具

H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法

ISO 26262 - 基于需求测试以外的考虑因素

【论文阅读】MAPS: Multi-agent Reinforcement Learning-based Portfolio Management System

Intelligent software analysis platform embold

Apifox interface integrated management new artifact

Cantata9.0 | new features
随机推荐
MySQL约束之默认约束default与零填充约束zerofill
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
Cantata9.0 | 全 新 功 能
目标:不排斥 yaml 语法。争取快速上手
Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system
FTP steps for downloading files from Huawei CE switches
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
Make this crmeb single merchant wechat mall system popular, so easy to use!
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
取两个集合的交集
机械臂速成小指南(十二):逆运动学分析
SQL注入报错注入函数图文详解
4G设备接入EasyGBS平台出现流量消耗异常,是什么原因?
ISO 26262 - 基于需求测试以外的考虑因素
openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
机械臂速成小指南(十一):坐标系的标准命名
Tensorflow2. How to run under x 1 Code of X