在面板上添加两个Label节点,一个Medal节点,放置到屏幕外,设置为隐藏。
在玩家碰撞时,激活该面板。
//碰撞开始
onCollisionEnter(other,self){
//显示游戏结束面板 --
cc.find('Canvas/base').active = true;
}
写一个脚本控制面板的动作和显示效果。
由于最高分要放置关闭游戏后被清除,将数据存储在硬件上,称为“数据持久化”。
cc.sys.localStorage.setItem(‘maxScore’,cc.maxScore);
cc.maxScore = cc.sys.localStorage.getItem(‘maxScore’);
//控制面板的动作
cc.Class({
extends: cc.Component,
properties: {
lbScore:cc.Label,
lbBestScroe:cc.Label,
modalN:cc.Node,
goldSpriteFrame:cc.SpriteFrame
},
start () {
//面板的动作
cc.tween(this.node)
.to(2.0,{position:cc.v2(0,0)})
.start();
//刷新分数标签
this.lbScore.string = cc.score; //当前分数(在GameMenu中定义的全局变量,在PipeLayer中玩家穿过水管时修改)
cc.maxScore = cc.maxScore < cc.score? cc.score:cc.maxScore;
this.lbBestScroe.string = cc.maxScore; //最高分数
//数据持久化(最高分)
cc.sys.localStorage.setItem('maxScore',cc.maxScore);
cc.maxScore = cc.sys.localStorage.getItem('maxScore');
},
//重新开始按钮的回调函数
btnReset(){
cc.director.loadScene('Main');
}
});