您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-x游戏得分显示

2015-10-17 10:58 429 查看
1、在程序.h文件中定义一个分数

int score=0;

2、在.cpp文件中添加一个分数层

//添加一个分数层

auto layer_score=Label::createWithBMFont(“helvetica-32.fnt”, “Score:0”);//Label::createWithBMFont表示添加图片字体,”helvetica-32.fnt”为图片字体的格式,”Score:0”表示在屏幕上显示的得分信息

this->addChild(layer_score,2);

layer_score->setPosition(375,1050);

layer_score->setScale(2);

layer_score->setTag(TAG_layer_Score);

3、在判定得分的位置添加得分规则

//加分

auto layer_score=(Label*)this->getChildByTag(TAG_layer_Score);

score+=nextTiled->number;//我引用的是2048游戏中的得分规则,表示分数等于现有分数加上两个相同块一个消失一个翻倍的中翻倍块上的数字

layer_score->setString(StringUtils::format(“Score:%d”,score));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: