標籤:style blog http io color os ar for sp
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**********************************/
Cocos2d JS 之消滅星星(七) 處理星星類之——排列星星