Cocos2d JS to destroy the Stars (11) Save player information locally

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.