0

我正在尝试使用此网站上的方法更新应用程序中的分数

http://fabiostemas.com.br/show-strings-using-numbers-in-cocos2d-x/

CCLabelBMFont *label2 = CCLabelBMFont::create(“分数:0”,“Arial.fnt”); addChild(label2, 100, kTagSprite2);

CCLabelBMFont* label2 = (CCLabelBMFont*) getChildByTag(kTagSprite2); label2->setString(stringPontos);

编译器给出错误:未在此范围内声明的 kTagSprite2 我如何声明 KTagSprite2 ,如什么类型?

4

1 回答 1

0

使用前必须先声明kTagSprite2,因为它不是关键字,也不是 cocos2d-x 声明的任何常量。所以给你..

我们可以将一个整数值作为标签分配给CCNodecocos2d 中的 any。

//Global declaration
#define kTagSprite2 1234

//Here you are setting kTagSprite2 or 1234 as tag value of label2

addChild(label2, 100, kTagSprite2);

//Here you are getting the child to which kTagSprite2 or 1234 is assigned as tag value
//i.e your label. This will return a child which has 1234 as its tag value

CCLabelBMFont* label2 = (CCLabelBMFont*) getChildByTag(kTagSprite2);
label2->setString(stringPontos);

希望这对您有所帮助。

于 2013-07-02T12:14:50.310 回答