六 CocosEditor基础教程第二季 之得分界面

前言:

这一节创建一个和pauseLayer差不多的scoreLayer界面,每个游戏结束都需要展示分数;

如果怪物被击中三次,显示结束分数界面;


效果图


六 CocosEditor基础教程第二季 之得分界面_第1张图片


代码下载

https://github.com/makeapp/cocoseditor-samples (snow-score



代码分析


1 创建ScoreLayer.ccbx主要里面的元素target是Owner自定义,而不是doc;

六 CocosEditor基础教程第二季 之得分界面_第2张图片



2 游戏结束函数;

从ccbx下载关联scoreData,that.scoreLayer = cc.BuilderReader.loadAsNodeFrom("", "ScoreLayer", scoreData);

scoreData里面有三个函数 一个显示星星个数的scoreGrade,根据你玩的情况给出评级,这里默认两个星;

另两个是按钮事件onScoreRenewClicked重新开始和onScoreNextClicked回到选关界面

MainLayer.prototype.gameOver = function () {
//show score layer
    this.gameStatus = END;
    this.currentLevelStarNum = 2;


    var that = this;
    this.rootNode.scheduleOnce(function () {
        var scoreData = {
            star1: {},
            star2: {},
            star3: {},

            scoreGrade: function () {
                var stars = [this.star1, this.star2, this.star3];
                for (var i = 0; i < stars.length; i++) {
                    if (i < that.currentLevelStarNum) {
                        stars[i].initWithSpriteFrameName("m_star_s.png");
                    }
                }
            },

            onScoreReplayClicked: function () {
                cc.Director.getInstance().resume();
                cc.BuilderReader.runScene("", "MainLayer");
            },

            onScoreLevelClicked: function () {
                cc.Director.getInstance().resume();
                cc.BuilderReader.runScene("", "GameSelectLayer");
            }

        };
        that.scoreLayer = cc.BuilderReader.loadAsNodeFrom("", "ScoreLayer", scoreData);
        that.scoreLayer.setPosition(cc.p(0.5, 0.5));
        that.scoreLayer.setZOrder(10000);
        that.rootNode.addChild(that.scoreLayer);
        cc.AudioEngine.getInstance().stopAllEffects();
        cc.AudioEngine.getInstance().stopMusic(true);

        scoreData.rootNode = that.scoreLayer;
        scoreData.controller = that;
        scoreData.scoreGrade();

        cc.Director.getInstance().pause();
    }, 0.5)
}

over;



你可能感兴趣的:(cocos2d-x,cocos2d-js,cocoseditor)