Cocos2d JS 之消滅星星(五) 遊戲主場景

 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 };
相關文章
相關標籤/搜索