当前位置:网站首页>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
边栏推荐
- Mongodb learn from simple to deep
- Spark judges that DF is empty
- 使用高斯Redis实现二级索引
- Solve the problem that the executable file of /bin/sh container is not found
- Measure the height of the building
- OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
- C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
- 让这个CRMEB单商户微信商城系统火起来,太好用了!
- 理财产品要怎么选?新手还什么都不懂
- uva 12230 – Crossing Rivers(概率)「建议收藏」
猜你喜欢

Mongodb learn from simple to deep

Measure the height of the building

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

OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验

机械臂速成小指南(十一):坐标系的标准命名

Network principle (1) - overview of basic principles

Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
Mysql子查询关键字的使用方式(exists)

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

智能软件分析平台Embold
随机推荐
恶魔奶爸 A3阶段 近常速语流初接触
开发一个小程序商城需要多少钱?
【函数递归】简单递归的5个经典例子,你都会吗?
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System
死锁的产生条件和预防处理[通俗易懂]
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
Mongodb learn from simple to deep
C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
Lingyun going to sea | yidiantianxia & Huawei cloud: promoting the globalization of Chinese e-commerce enterprise brands
margin 等高布局
Jenkins 用户权限管理
[function recursion] do you know all five classic examples of simple recursion?
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
Klocwork 代码静态分析工具
静态测试工具
OneSpin | 解决IC设计中的硬件木马和安全信任问题
openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
Introduction to referer and referer policy
Small guide for rapid formation of manipulator (12): inverse kinematics analysis