加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 21:36:37 所属栏目:百科 来源:网络整理
导读:Cocos2d-js06-添加分数和死亡判断 1、添加分数,代码: // 添加分数 score = new cc . LabelTTF ( " 分数 :0" , "Arial" , 50 ); score . setPosition ( cc . p ( winSize . width / 2 , winSize . height - 130 )); this . addChild ( score , 4 ); // 添加

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 后期也会把该源码传在群里面去,欢迎大家加入讨论!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读