在这里,这可能会奏效
在.h文件中:
@interface HelloWorld : CCLayer {
int score;
CCLabelTTF *scoreLabel;
}
- (void)addPoint;
Run Code Online (Sandbox Code Playgroud)
在.m文件中:
在init方法中:
//Set the score to zero.
score = 0;
//Create and add the score label as a child.
scoreLabel = [CCLabelTTF labelWithString:@"8" fontName:@"Marker Felt" fontSize:24];
scoreLabel.position = ccp(240, 160); //Middle of the screen...
[self addChild:scoreLabel z:1];
Run Code Online (Sandbox Code Playgroud)
别的地方:
- (void)addPoint
{
score = score + 1; //I think: score++; will also work.
[scoreLabel setString:[NSString stringWithFormat:@"%@", score]];
}
Run Code Online (Sandbox Code Playgroud)
现在只需致电:[self addPoint]; 每当用户杀死敌人时.
这应该工作,告诉我,如果没有,因为我没有测试它.
| 归档时间: |
|
| 查看次数: |
10111 次 |
| 最近记录: |