我正在 cocos2d 中制作一个游戏,在更新分数时,旧分数值会出现在标签上,而新值会被覆盖。我正在使用以下代码来显示分数,
LblScore = [CCLabel labelWithString:[NSString stringWithFormat:@"%d",score]
dimensions:CGSizeMake(100, 300)
alignment:UITextAlignmentCenter
fontName:@"Arial"
fontSize:32.0];
因此,分数值不会显示,所有事情都会变得一团糟,如果有人知道如何更新新分数?
我不完全明白你在做什么,因为我看不到你的所有代码。但是,我认为你想要的是这样的:
在你的场景初始化中:
// Both of these are class variables
score = 0;
LblScore = [CCLabel labelWithString:[NSString stringWithFormat:@"%d",score] dimensions:CGSizeMake(100, 300) alignment:UITextAlignmentCenter fontName:@"Arial" fontSize:32.0];
// Position the score, wherever you want it
[LblScore setPosition: CGPointMake(300, 240)];
当你的分数发生变化时:
score++ // Not really, but your score changes somehow...
[LblScore setString: [NSString stringWithFormat:@"%d",score]];
这部分可能会在setScore:
or changeScore:
改变你的内部分数值并同时改变标签的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)