Save data

Save data
0.0 0



we are developing a little game using this engine.

We are deploying the game to iPhone and we need to know how to save the data progress.

Kind regards.


Save data via fopen/fwrite or libxml2 is recommended.
I prefer the first one, fwrite a whole structure into binary file.


On Android writing to file require WRITE_EXTERNAL_STORAGE permission, may be we should wrap SharedPreferences and NSUserDefaults to CCUserPreferences?


NSUserDefaults offers more feature than SharedPreferences. What data types should CCUserPreferences offer?


I wrote android implementation with next types:
* bool
* int
* float
* string


Suggestion for my pull-request and CCUserPreference interface

May be better instead
@ int getInteger(const std::string& key, int defaultValue); @
@ bool getInteger(const std::string& key, int* value); @
and return true for success retrieving or false otherwise?

Then we can avoid useless std::string copying in getString and handle error when trying getting data other type than preference with requested key have.


Thanks for your contribution! But I cannot merge it directly to cocos2dx folder.
We are considering to create a new folder parallels with cocos2dx, to put in your CCUserDefault, and our CCEditor(#317) & CCVibration(#444) in future. It can be named as “extra”, or “cocross” as my idea, :slight_smile:
issue #455 is created for CCUserPreference


Totally agreed :slight_smile: