1 /*
2 * 本層擁有處理星星的實例化以及對星星的操做
3 */
4 var GameStarLayout = ccui.Layout.extend(
5 {
6 size:null,
7 starArr:[],//存放點擊與被點擊狀態的星星資源
8 starObjArr:[],//存放遊戲中星星的二位數組
9 ctor:function()
10 {
11 this._super();
12 this.zinit();
13 this.layoutStar();
14 },
15 //將星星按10*10的矩陣排列出來
16 layoutStar:function()
17 {
18 for(var i = 0; i < 10; i++)
19 {
20 for(var j = 0; j < 10; j++)
21 {
22 //隨機從5種不一樣顏色的星星中選擇一個
23 var randomNumber = Math.floor(Math.random()*this.starArr.length);
24 var starResource = this.starArr[randomNumber];
25 var star = new GameCreateStar(starResource.normal, starResource.id,starResource.selected);
26 this.addChild(star, 0);
27 //星星出現的動畫
28 var moveTo = cc.moveTo(i/10, cc.p(star.width*i, star.height*j));
29 star.runAction(moveTo);
30 //將星星裝到數組中
31 this.starObjArr[i][j] = star;
32 }
33 }
34 },
35 //初始化
36 zinit:function()
37 {
38 this.size = cc.size(480, 500);
39 //設置層的大小
40 this.setSize(this.size);
41 //將星星資源存放到數字中
42 this.starArr = [
43 {id:1, normal:res.star1, selected:res.star1s},
44 {id:2, normal:res.star2, selected:res.star2s},
45 {id:3, normal:res.star3, selected:res.star3s},
46 {id:4, normal:res.star4, selected:res.star4s},
47 {id:5, normal:res.star5, selected:res.star5s}
48 ];
54 }
55 });
56 //實例化
57 GameStarLayout.createLayout = function()
58 {
59 var starLayout = new GameStarLayout();
60 return starLayout;
61 };
/********************************effect image**********************************/