Cocos2d-js06-添加分数和死亡判断

Cocos2d-js06-添加分数和死亡判断,第1张

概述Cocos2d-js06-添加分数和死亡判断 1、添加分数,代码: //添加分数 score = new cc.LabelTTF("分数:0", "Arial", 50);score.setPosition(cc.p(winSize.width/2,winSize.height - 130));this.addChild(score,4);   //添加分数 this.m_score += 1

Cocos2d-Js06-添加分数和死亡判断

1、添加分数,代码:

//添加分数 score = new cc.LabelTTF("分数:0","Arial",50);score.setposition(cc.p(winSize.wIDth/2,winSize.height - 130));this.addChild(score,4);
//添加分数 this.m_score += 100;score.setString("分数:"+this.m_score);
 
2、死亡判断,代码:

//走出边界,游戏结束
if(this._head.Now_col < 0 || this._head.Now_row < 0 || this._head.Now_col >= 10 || this._head.Now_row >= 10){
this.onGameOver();
}

//蛇头碰到蛇尾,游戏结束
if(SNAKE_BODY.length != 0){
for(var i = SNAKE_BODY.length - 1; i >= 0; i--){
if(this._head.Now_col== SNAKE_BODY[i].Now_col&& this._head.Now_row== SNAKE_BODY[i].Now_row){
this.onGameOver();
}
}
}

3、onGameOver方法:

onGameOver:function(){
director.pause();
var gameOver= new cc.LabelTTF("GameOver!", 50);
var over = new cc.MenuItemLabel(gameOver,function(){
window.location.href = "http://h5.9miao.com";
});
over.setposition(cc.p(size.wIDth/2,size.height/2));
var menu = new cc.Menu(over);
menu.x = 0;
menu.y = 0;
this.addChild(menu,5);

},


视频地址:http://www.9miaoketang.com/course/37 课程讨论帖地址:http://www.9miao.com/thread-64587-1-1.HTML 源码地址:https://store.cocos.com/stuff/show/128289.HTML QQ交流群:83459374 后期也会把该源码传在群里面去,欢迎大家加入讨论!

总结

以上是内存溢出为你收集整理的Cocos2d-js06-添加分数和死亡判断全部内容,希望文章能够帮你解决Cocos2d-js06-添加分数和死亡判断所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1062358.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存