coco2dx中基础的数据存储

  在做游戏的过程中基础的数据存储是必须丶,而最基础的无疑是存储游戏的得分多少,就是简简单单的存储一个游戏的得分。


那么如何去存储呢?在cocos2d-x3.0中我们可以使用UserDefault来实现简单的存储得分。

那么可以看一下源代码

     <pre name="code" class="cpp">//get类的函数表示得到的值    
bool getBoolForKey(const char* pKey); bool getBoolForKey(const char* pKey, bool defaultValue); int getIntegerForKey(const char* pKey); int getIntegerForKey(const char* pKey, int defaultValue); float getFloatForKey(const char* pKey); float getFloatForKey(const char* pKey, float defaultValue); double getDoubleForKey(const char* pKey); double getDoubleForKey(const char* pKey, double defaultValue); std::string getStringForKey(const char* pKey); std::string getStringForKey(const char* pKey, const std::string & defaultValue); Data getDataForKey(const char* pKey); Data getDataForKey(const char* pKey, const Data& defaultValue);

//set类的函数表示设置值为多少

       void    setBoolForKey(const char* pKey, bool value);
       void    setIntegerForKey(const char* pKey, int value);
       void    setFloatForKey(const char* pKey, float value);
       void    setDoubleForKey(const char* pKey, double value);
       void    setStringForKey(const char* pKey, const std::string & value);
      void    setDataForKey(const char* pKey, const Data& value);

<pre name="code" class="cpp">//由此可以得知我们可以通过唯一的标识来存储每一个数据。
//而它的底层是通过用XML自定义标签来保存数据的大体如下
 
<?xml version="1.0" encoding="UTF-8"?>  
<userDefaultRoot>  
<mydate>1223</mydate>  
</userDefaultRoot>  
 大体如上所示如果说大家想存储比较多的数据,可以采用SQLite来存储。 

 
<a target=_blank href="http://cn.cocos2d-x.org/tutorial/show?id=1723">详情查看链接</a>
</pre><pre name="code" class="cpp">

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值