Cocos2d JS 之消滅星星(七) 處理星星類之——排列星星

來源:互聯網
上載者:User

標籤: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 之消滅星星(七) 處理星星類之——排列星星

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.