首页 > 代码库 > Cocos2d JS 之消灭星星(四) 游戏主场景顶部显示

Cocos2d JS 之消灭星星(四) 游戏主场景顶部显示

  1 /*  2  * 游戏主场景顶部显示信息  3  */  4 var GameTopInformation = ccui.Layout.extend(  5 {  6     size:null,  7     isPause:false,//是否暂停游戏  8     maxScoreLabel:null,//最高纪录  9     getScoreNum:null,//当前得分 10     currentLevel:null,//当前关卡 11     ctor:function() 12     { 13         this._super(); 14         this.zinit(); 15         this.setInformation(); 16     }, 17     //信息设置 18     setInformation:function() 19     { 20         var maxRecord = new myImage(res.maxrecord); 21         maxRecord.x = 10; 22         maxRecord.y = this.size.height - maxRecord.height - 20; 23         this.addChild(maxRecord, 1); 24  25         var maxScore = new myImage(res.maxscore); 26         maxScore.x = maxRecord.x + maxRecord.width + 30; 27         maxScore.y = maxRecord.y; 28         this.addChild(maxScore, 1); 29  30         this.maxScoreLabel = new myText("0", white, 26); 31         this.maxScoreLabel.x = maxScore.x+(maxScore.width - this.maxScoreLabel.width)/2; 32         this.maxScoreLabel.y = maxScore.y; 33         this.addChild(this.maxScoreLabel, 2); 34         //暂停和继续游戏控制按钮 35         var pauseGameBtn = new myButton(res.pause); 36         pauseGameBtn.x = this.size.width - pauseGameBtn.width - 10; 37         pauseGameBtn.y = this.maxScoreLabel.y; 38         this.addChild(pauseGameBtn, 1); 39         pauseGameBtn.addTouchEventListener(this.pauseGameBtnFunc, this); 40         //过关text 41         var guoguanImg = new myImage(res.guoguan); 42         guoguanImg.x = 0; 43         guoguanImg.y = maxRecord.y - guoguanImg.height - 20; 44         this.addChild(guoguanImg, 1); 45         //当前关卡 46         var currentLevelImg = new myImage(res.level); 47         currentLevelImg.x = guoguanImg.x + guoguanImg.width; 48         currentLevelImg.y = guoguanImg.y; 49         this.addChild(currentLevelImg, 1); 50          51         this.currentLevel = new myText("1", white, 24); 52         this.currentLevel.x = currentLevelImg.x + (currentLevelImg.width -this.currentLevel.width)/2 53         this.currentLevel.y = currentLevelImg.y; 54         this.addChild(this.currentLevel, 1); 55         //目标分数 56         var targetImg = new myImage(res.target); 57         targetImg.x = currentLevelImg.x + currentLevelImg.width + 20; 58         targetImg.y = currentLevelImg.y; 59         this.addChild(targetImg, 1); 60          61         var targetImgbg = new myImage(res.targetBar); 62         targetImgbg.x = this.size.width - targetImgbg.width - 10; 63         targetImgbg.y = targetImg.y; 64         this.addChild(targetImgbg, 1); 65          66         var targetScore = new myText("1000", white, 25); 67         targetScore.x = targetImgbg.x +(targetImgbg.width - targetScore.width)/2; 68         targetScore.y = targetImgbg.y; 69         this.addChild(targetScore, 1); 70         //得分 71         var getScore = new myImage(res.defen); 72         getScore.x = this.size.width - getScore.width >> 1; 73         getScore.y = targetScore.y - getScore.height - 10; 74         this.addChild(getScore, 1); 75          76         var getScoreBg = new myImage(res.defenBar); 77         getScoreBg.x = this.size.width - getScoreBg.width >> 1; 78         getScoreBg.y = getScore.y - getScoreBg.height - 10; 79         this.addChild(getScoreBg, 1); 80          81         this.getScoreNum = new myText("000", white, 25); 82         this.getScoreNum.x = this.size.width - this.getScoreNum.width>>1; 83         this.getScoreNum.y = getScoreBg.y; 84         this.addChild(this.getScoreNum, 1); 85          86     }, 87     //暂停和继续游戏控制按钮侦听函数 88     pauseGameBtnFunc:function(target, state) 89     { 90         if(state == ccui.Widget.TOUCH_ENDED)//松开 91         { 92             if(this.isPause) 93             { 94                 cc.log("is game pause"); 95                 target.setOpacity(255); 96                 this.isPause = false; 97             } 98             else 99             {100                 cc.log("continue game");101                 target.setOpacity(150);102                 this.isPause = true;103             }104         }105     },106     //初始化107     zinit:function()108     {109         this.size = cc.size(480, 300);110         this.setSize(this.size);111     }112 });
/**************************effect image*******************************/

 

Cocos2d JS 之消灭星星(四) 游戏主场景顶部显示