我有一個類,我打算重複使用多個級別的遊戲,並且遇到更新標籤文本的問題。基本上,我試圖重複使用這個遊戲的15個級別。所以最初標籤的值是1,然後在清除關卡之後它應該增加1,然後重新加載更新後的文本。這是我正在努力更新我的標籤:標籤文本沒有更新(cocos2d)
GameScene *stage= [stage node];
[[CCDirector sharedDirector]replaceScene:stage];
//stageNo is an integer that I pass to the label as it's text value. As long as its less that 15, it should go inside that code block.
if(stageNo < 15)
{
stageNo = stageNo + 1;
[stage.layer.stageLabel setString:[NSString stringWithFormat:@"%i", StageNo]];
}
這隻能只有一次,所以如果標籤的缺省值是1,級別重新加載後變爲2之後,它只是卡住到2.所以我的問題是,我怎麼能更新標籤文本,每當類重新加載1?
如何/你在哪裏設立stageLabel開始? – 2013-02-11 07:22:56
我在頭文件類上設置爲CCLabelTTF,然後在init方法中,我將stageNo設置爲1,然後我添加了這個:stageLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@「%@」,stageNo] fontName:@「 Arial「fontSize:18]; – user1597438 2013-02-11 07:38:20
聽起來像範圍問題。如果只在init方法中本地創建stageLabel,則其餘代碼不知道其存在。嘗試使它成爲一個伊娃或財產。 – 2013-02-11 07:43:55