1 /* 2 * 游戏过渡场景,主要作用是在每次进入游戏或者进入下一关卡时进行过渡,显示当前的关卡以及通过该关卡要达到的分数; 3 */ 4 var TransitionScene = ccui.Layout.extend( 5 { 6 size:null, 7 ctor:function(isNewGame) 8 { 9 this._super();10 this.isNewGame = isNewGame;11 this.zinit();12 this.setLabel();13 this.gotoGameMainScene();14 },15 //设置显示文本(当前关卡数,通过关卡分数)16 setLabel:function()17 {18 //当前进入关卡19 var currentLevel = new myText("level "+this.levelNumber.toString(),white, 20);20 currentLevel.x = this.size.width - currentLevel.width >> 1;//居中21 currentLevel.y = 500;22 this.addChild(currentLevel, 1);23 24 var targetTxt = new myText("target score is", white, 20);25 targetTxt.x = this.size.width - targetTxt.width >> 1;26 targetTxt.y = currentLevel.y - targetTxt.height - 10;27 this.addChild(targetTxt, 1);28 //通关分数29 var targetScore = new myText(this.standardScore.toString(), white, 20);30 targetScore.x = this.size.width - targetScore.width >> 1;31 targetScore.y = targetTxt.y - targetScore.height - 10;32 this.addChild(targetScore, 1);33 },34 //进入游戏主场景35 gotoGameMainScene:function()36 {37 //两秒后进入游戏主界面38 this.scheduleOnce(function()39 {40 var gMainScene = GameMainScene.createScene();41 cc.director.runScene(cc.TransitionFade.create(1, gMainScene));42 }, 2);43 },44 //初始化45 zinit:function()46 {47 //设置布局大小48 this.size = cc.size(480, 800);49 this.setSize(this.size);50 //实例化背景图片51 var backGround = new myImage(res.mainbacktop);52 backGround.y = this.size.height - backGround.height;53 this.addChild(backGround, 0);54 var backGround1 = new myImage(res.mainbackbottom);55 this.addChild(backGround1, 0);56 57 //初始化玩家信息58 if(this.isNewGame == true)59 {60 PlayerLocalData.deleteItem();61 }62 this.playerGameData = PlayerLocalData.getItem();63 //这里要注意,第一次进入游戏时,this.playerGameData是一个数组,之后就变成对象了,这里确保游戏中统一用对象64 if(this.playerGameData.length == true)65 {66 this.playerGameData = this.playerGameData[0];67 }68 else69 {70 this.playerGameData = this.playerGameData;71 }72 this.levelNumber = this.playerGameData.currentLevel;//当前关卡数字73 //获得当前关卡的目标分数74 for(var i = 0; i < levelData.length; i++)75 {76 if(this.levelNumber == levelData[i].level)77 {78 this.standardScore = levelData[i].standards;79 break;80 }81 }82 }83 });84 //实例化场景85 TransitionScene.createScene = function(isNewGame)86 {87 var tScene = cc.Scene.create();88 var tLayout = new TransitionScene(isNewGame);89 tScene.addChild(tLayout);90 return tScene;91 };
/******************************effect image****************************/