End of Game interface:
In the previous tutorials, the interface of the creation of the required knowledge point basic we have talked about, here is the user data cache, it is also first to see the source
/** * Power by HTML5 Chinese web (html5china.com) * AUTHOR:JACKYWHJ*/varGameover =cc. Layer.extend ({init:function () { varBRet =false; if( This. _super ()) { varSP =cc. Sprite.create (S_B05); Sp.setanchorpoint (CC.P (0,0) ); This. AddChild (SP, 0, 1); varLogo =cc. Sprite.create (S_gameover); Logo.setanchorpoint (CC.P (0,0)); Logo.setposition (20,350); This. AddChild (logo,10,1); varPlayagainnormal = cc. Sprite.create (S_menu, Cc.rect (378, 0, 126, 33)); varplayagainselected = cc. Sprite.create (S_menu, Cc.rect (378, 33, 126, 33)); varplayagaindisabled = cc. Sprite.create (S_menu, Cc.rect (378, 33 * 2, 126, 33)); varPlayagain = cc. Menuitemsprite.create (Playagainnormal, playagainselected, playagaindisabled,function() {Flareeffect ( This, This, This. Onplayagain); }.bind ( This) ); varmenu =cc. Menu.create (Playagain); This. AddChild (menu, 1, 2); Menu.setposition (Winsize.width/2, 280); if(!localstorage.getitem ("Bestscore") {Localstorage.setitem ("Bestscore", g_sharedgamelayer._timestring); }; varLbscore = cc. Labelttf.create ("Time" +g_sharedgamelayer._timestring, "Forte", 26); Lbscore.setposition (Winsize.width/2,200); Lbscore.setcolor (CC.C3B (200,38,12));//Lbscore.enablestroke (cc.c3b (0,0,0), +); This. AddChild (lbscore,10); varbeststring = Localstorage.getitem ("Bestscore"); varBestarr = Beststring.split (":"); varstime = bestarr[0]*60 + bestarr[1]; if(Stime >g_sharedgamelayer._time) {Localstorage.setitem ("Bestscore", g_sharedgamelayer._timestring); } varBestscore = cc. Labelttf.create ("best time" + Localstorage.getitem ("Bestscore"), "Forte", 26); Bestscore.setposition (180,150); Bestscore.setcolor (CC.C3B (200,38,12)); This. AddChild (bestscore,10); if(Llk. Sound) {cc. Audioengine.getinstance (). Playmusic (S_mainmainmusic_mp3); } BRet=true; } returnBRet; }, Onplayagain:function(psender) {varScene =cc. Scene.create (); Scene.addchild (Gamelayer.create ()); Scene.addchild (Gamecontrolmenu.create ()); Cc. Director.getinstance (). Replacescene (CC. Transitionfade.create (1.2, Scene)); }}); Gameover.create=function () { varSG =NewGameover (); if(SG &&Sg.init ()) { returnSG; } return NULL;}; Gameover.scene=function () { varScene =cc. Scene.create (); varLayer =gameover.create (); Scene.addchild (layer); returnscene;};
The cache of game data here is done using local cache localstorage.
if (!localstorage.getitem ("Bestscore")) { Localstorage.setitem ("Bestscore"), G_sharedgamelayer._ timestring); }; var lbscore = cc. Labelttf.create ("Time" +g_sharedgamelayer._timestring, "Forte", +); /2,200); Lbscore.setcolor (cc.c3b (200,38,12)); // Lbscore.enablestroke (cc.c3b (0,0,0), +); this. AddChild (lbscore,10);
first of all, we first determine whether there is the ontology cache data, does not exist, we will add the cache data and the current game time through cc. The Labelttf is added to the layer . Cached data is present, we take out the cached data and compare it to the current game, then cache the best scores and add them to the layer
var beststring = Localstorage.getitem ("Bestscore"); var bestarr = Beststring.split (":"); var stime = bestarr[0]*60 + bestarr[1]; if (Stime > g_sharedgamelayer._time) { Localstorage.setitem ("Bestscore", G_sharedgamelayer._ timestring); }