cocos2dx getChildByTag函数,声明标记

时间:2013-07-02 09:02:25

标签: cocos2d-x

我正在尝试使用此网站的方法更新应用中的得分

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

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

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

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

1 个答案:

答案 0 :(得分:0)

您必须在使用之前声明kTagSprite2,因为它不是cocos2d-x声明的关键字或任何常量。所以,你走了..

我们可以将整数值作为标记分配给cocos2d中的任何CCNode

//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);

希望这会对你有所帮助。