After the player has retired to the game, the next time you enter the game, you can continue with the last game progress;
1 /*2 * Local storage of player data under Win73 */4 varPlayerlocaldata = {};5 /*6 * Player Data structure7 */8 varPlayerdata =function()9 {Ten varPlayerd = [ One { ACurrentlevel:1,//player Level -gamescore:0,//Game Score -maxscore:0//Maximum game score the }]; - returnPlayerd; - }; - + /* - * Write data to save player data locally + * @param jsonname the name of the incoming JSON data structure A */ atPlayerlocaldata.setitem =function(Jsonname) - { - varplayerdd= json.stringify (jsonname);//converting a JSON data structure into a string structure -Sys.localStorage.setItem ("Playerdata", Playerdd);//Write Data - }; - in /* - * Read the player data and return the JSON data Format (array) to */ +Playerlocaldata.getitem =function() - { the if(!sys.localstorage.getitem ("Playerdataexist")) * { $ varPlayerData1 =json.stringify (Playerdata ());Panax Notoginseng //only the first time the player enters the game will the initial player data be written -Sys.localStorage.setItem ("Playerdataexist", "Playerdataexist"); theSys.localStorage.setItem ("Playerdata", playerData1); + } A varPlayerdataa = Sys.localStorage.getItem ("Playerdata");//read data from local thePlayerdataa = Json.parse (PLAYERDATAA);//Convert a string structure to a JSON data structure + returnPlayerdataa; - }; $ $ /* - * Delete data to erase player data - */ thePlayerlocaldata.deleteitem =function() - {WuyiSys.localStorage.removeItem ("Playerdata"); theSys.localStorage.removeItem ("Playerdataexist"); -};
Cocos2d JS to destroy the Stars (11) Save player information locally