StatusLayer 加入两个成员函数,用来更新coin数量和meter距离。
切换到PlayScene.js
collisionCoinBegin做如下处理
var statusLayer = this.getChildByTag(TagOfLayer.Status);
statusLayer.addCoin(1);
切换到AnimationLayer.js, 在update中加入下面的代码。
// update meter
var statusLayer = this.getParent().getChildByTag(TagOfLayer.Status);
statusLayer.updateMeter(this.sprite.getPositionX() - g_runnerStartX);
是一个Color Layer,半透明浮在游戏界面上,中间一个restart游戏的button按钮。
在PlayScene的collisionRockBegin 加入game over 逻辑
collisionRockBegin:function (arbiter, space) {
cc.Director.getInstance().pause();
this.addChild(new GameOverLayer());
},
注意,我们让Director暂停了,为了restart的时候能重新游戏。我们在PlayScene的onEnter加入
cc.Director.getInstance().resume();
分三点分别解析。