我有一个类,我打算重复使用多个级别的游戏,并且遇到更新标签文本的问题。基本上,我试图重复使用这个游戏的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