新手抓星星小游戏游戏结束时按键不显示,但是点击结束时按键应该出现的位置会有效,如何让开始按键和游戏结束标签显示出来?再就是对星星的销毁函数没有起作用,请问如何真正起作用,有效销毁上一局未被销毁的星星?不然每一局比上一局多一个星星,麻烦大佬帮我看一下哪出问题了,谢万分感谢。
gameOver:function()
{
this.btnNode.x=0;
this.player.enabled=false;
this.GameOverNode.active=true;
this.Star.destroy();
},
game over时图片:
另有载入函数:
onLoad:function()
{
//获取地平面y轴坐标,this.ground.y是地面中心的坐标,后面的是部件的高度。
this.groundY=this.ground.y+this.ground.height/2;
this.currentStar=null;//新增
this.currentStarX=0;//新增
//初始化计时器
this.timer=0;
this.starDuration=0;
this.enabled=false;
var hintText = cc.sys.isMobile ? this.touchHint : this.keyboardHint;
this.controlHintLabel.string = hintText;//以上两行新增
this.score=0;
this.starPool = new cc.NodePool('Star');//新增
//this.playAgainNode.x=3000;
},
onStartGame:function(){
this.spawnNewStar();//先产生星星,不立马产生星星,星星周期是0,
this.resetScore();
this.enabled = true;
this.btnNode.x = 3000;
this.gameOverNode.active = false;
this.player.startMoveAt(cc.v2(0, this.groundY));
},
官方教程里的写法:
onLoad: function () {
this.groundY = this.ground.y + this.ground.height/2;
// store last star's x position
this.currentStar = null;
this.currentStarX = 0;
// 初始化计时器
this.timer = 0;
this.starDuration = 0;
// is showing menu or running game
this.enabled = false;
// initialize control hint
var hintText = cc.sys.isMobile ? this.touchHint : this.keyboardHint;
this.controlHintLabel.string = hintText;
// initialize star and score pool
this.starPool = new cc.NodePool('Star');
this.scorePool = new cc.NodePool('ScoreFX');
},
onStartGame: function () {
// 初始化计分
this.resetScore();
// set game state to running
this.enabled = true;
// set button and gameover text out of screen
this.btnNode.x = 3000;
this.gameOverNode.active = false;
// reset player position and move speed
this.player.startMoveAt(cc.v2(0, this.groundY));
// spawn star
this.spawnNewStar();
},
gameOver: function () {
this.gameOverNode.active = true;
this.player.enabled = false;
this.player.stopMove();
this.currentStar.destroy();
this.btnNode.x = 0;
}
麻烦大佬帮我看一下哪出问题了?万分感谢。
