2013-07-02 58 views
0

我試圖利用該方法從這個網站更新的應用程序評分標籤cocos2dx getChildByTag功能,宣稱

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

CCLabelBMFont *標籤2 = CCLabelBMFont ::創建(「分數:0「,「 Arial.fnt「); addChild(label2,100,kTagSprite2);

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

編譯器給出錯誤:kTagSprite2未在此範圍內聲明 如何聲明KTagSprite2,如何在哪種類型中?

回答

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

希望這可以幫助你。