Can any one tell me how to save game data with a good way without lost data when game update or user clear/delete data in android app setting?. I saw in cocos2d-x has UserDefault but when my game update to new version my old data like score, diamonds alway lost.
I know it worked but the thing that I care the most is about game update. example if i release first version on google play and I want give old user update to next version then all data for those old user will lost. or UserDefault also work with that situation too.
If the device is rooted/jailbreaked the data is visible, because it’s not encrypted. Without root/jailbreak the data is only “app visible”, so no other app can access it.
Every data which should stay after game delete has to be world readable (at least on Android). So every app can read/edit it. Do you really want that?
The best way to save data even after a game delete, is to use server side savegames and on your device you just save a UUID (key on sever) in the UserDefaults (which are backed up by the system and reinstalled even on a new device).
what about data in the resourcefolder, I’ve seen its possible to Create data in the resource Folder and read/write from it, but not sure how data from the resoruce folder is handled? is everything there transformed to binary into the apk?
Everything in resource will be unaltered in the assets folder of the APK. But this folder ist readonly at runtime, because it’s never unpacked elsewhere.
kinda solved this myself, Cocos will always try to load from the resource file in the apk/release Folder, and writing only happens to the Project resource Folder.
In my case i want to be able to modify Levels in the game and save them to the resource Folder for PC Debug only (kinda like a Custom Editor).
The solution to this was just to Create a save function that ready from the full Project Resource path (just enter the full path to the prohect reosurce Folder, so it doesnt try to read from the release resource Folder) but for saving use the normal path (since saving will write to the Project resource path anyway)
And for the reading function just use the normal relative path, which will be the release resource Folder.
Read()
const std::string content = FileUtils::getInstance()->getStringFromFile(file_path); //reads from release Resource
Write()
const std::string file_path = "E:/Projects/myproject/myproject/Resources/" + target_file; //read first
auto content = FileUtils::getInstance()->getStringFromFile(file_path);
//find Something in the fild and replace
FileUtils::getInstance()->writeStringToFile(content , target_file);; //write the Changes to file
I would prefer to always use lower case file-/folder-names. And if it’s Resource/level/level1.txt while compile time, you just use level/level1.txt to reference it, because there is no Resource folder on Android.
I would be confused if this will be working in the release build, because you can’t change any files on runtime in the assets store of the APK.
If you use it only on the PC, it’s a different story and was not your question at first.