1 /*2 * This layer has an instantiation of star handling and manipulation of stars3 */4 varGamestarlayout =Ccui. Layout.extend (5 {6SizeNULL,7Stararr:[],//The star resource that holds the clicked and clicked State8Starobjarr:[],//two-bit array to store stars in the game9ctorfunction()Ten { One This. _super (); A This. Zinit (); - This. Layoutstar (); - }, the //The stars are arranged in 10*10 matrix. -Layoutstar:function() - { - for(vari = 0; I < 10; i++) + { - for(varj = 0; J < 10; J + +) + { A //randomly select one of 5 different color stars at varRandomnumber = Math.floor (Math.random () * This. stararr.length); - varStarresource = This. Stararr[randomnumber]; - varStat {NewGamecreatestar (Starresource.normal, starresource.id,starresource.selected); - This. AddChild (Star, 0); - //The animated stars appear - varMoveTo = Cc.moveto (I/10, CC.P (Star.width*i, star.height*j)); in star.runaction (moveTo); - //Put the stars in the array to This. starobjarr[i][j] =Star; + } - } the }, * //Initialize $Zinit:function()Panax Notoginseng { - This. Size = Cc.size (480, 500); the //to set the size of a layer + This. SetSize ( This. Size); A //storing star resources in numbers the This. Stararr = [ +{id:1, Normal:res.star1, Selected:res.star1s}, -{Id:2, Normal:res.star2, selected:res.star2s}, ${Id:3, Normal:res.star3, selected:res.star3s}, ${Id:4, NORMAL:RES.STAR4, selected:res.star4s}, -{Id:5, NORMAL:RES.STAR5, selected:res.star5s} - ];
Wu } - }); About //instantiation of $Gamestarlayout.createlayout =function() - { - varStarlayout =Newgamestarlayout (); - returnstarlayout; A};
/********************************effect image**********************************/
Cocos2d JS to destroy the Stars (vii) dealing with stars--arranging stars