1 /* 2 * 游戏主场景 3 */ 4 var playerGameData;//玩家信息 5 var GameMainScene = ccui.Layout.extend( 6 { 7 ctor:function() 8 { 9 this._super(); 10 this.zinit(); 11 this.setTopInfor(); 12 this.addStarLayout(); 13 }, 14 //游戏主场景顶部显示信息 15 setTopInfor:function() 16 { 17 //初始化玩家信息 18 playerGameData = PlayerLocalData.getItem(); 19 //这里要注意,第一次进入游戏时,playerGameData是一个数组,之后就变成对象了,这里确保游戏中统一用对象 20 if(playerGameData.length == true) 21 { 22 playerGameData = playerGameData[0]; 23 } 24 else 25 { 26 playerGameData = playerGameData; 27 } 28 var gameTopInfo = new GameTopInformation(); 29 gameTopInfo.y = this.size.height - gameTopInfo.height; 30 this.addChild(gameTopInfo, 1); 31 }, 32 //将星星层添加到主场景 33 addStarLayout:function() 34 { 35 var starLayout = GameStarLayout.createLayout(); 36 this.addChild(starLayout, 1); 37 }, 38 //初始化 39 zinit:function() 40 { 41 //设置布局大小 42 this.size = cc.size(480, 800); 43 this.setSize(this.size); 44 //实例化背景图片 45 var backGround = new myImage(res.mainbacktop); 46 backGround.y = this.size.height - backGround.height; 47 this.addChild(backGround, 0); 48 var backGround1 = new myImage(res.mainbackbottom); 49 this.addChild(backGround1, 0); 50 } 51 }); 52 53 54 GameMainScene.createScene = function() 55 { 56 var gameLayout = new GameMainScene(); 57 var scene = cc.Scene.create(); 58 scene.addChild(gameLayout); 59 return scene; 60 };