I’m converting my game from cocos2d-x 2.2.3 to cocos2d-js 3.2, but the players already have saved progress using the old CCUserDefaults. Now that I have to use localStorage in cocos2d-js, how can I read the old data that was saved using CCUserDefaults? I don’t want players to lose their progress after the update.
I think the simplest way would be to have a final v2.x update in which you make the game to migrate data from CCUserDefaults
to the browser's localstorage, then when you migrate your game to v3.x you can swap the standard localstorage for coco's implementation if you want to. Note that coco's implementation is really only useful because it abstracts you from doing the localstorage code yourself and makes the same API work if you were to compile your code for Android or other platforms.
The standard HTML5 localstorage usage goes like:
.A
localStorage.setItem("handle", "value");
var result = localStorage.getItem("handle");
console.log(result); //Should print "value"
.B
localStorage.handle = "value";
var result = localStorage.handle;
console.log(result); //Should print "value"