zoukankan      html  css  js  c++  java
  • Cocos2d JS 之消灭星星(三) 进入游戏过渡场景

    
    
     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         else
    69         {
    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****************************/
    
    
  • 相关阅读:
    笔记:今天必须读完的文章
    windows android 第三方模拟器 看日志
    彻底搞懂Android文件存储---内部存储,外部存储以及各种存储路径解惑
    texturepacker命令行处理图片 格式选择
    Android插件化主流框架和实现原理
    Socket心跳包机制与实现 一般的应用下,判定时间在30-40秒比较不错。如果实在要求高,那就在6-9秒。
    图解:HTTP 范围请求,助力断点续传、多线程下载的核心原理
    localstorage的跨域存储方案 介绍
    UGUI的图集处理方式-SpriteAtlas的前世今生
    web自动化,下拉滚动到底部/顶部和下拉滚动到指定的元素
  • 原文地址:https://www.cnblogs.com/zfsSuperDream/p/4057670.html
Copyright © 2011-2022 走看看