use*_*293 9 iphone cocoa-touch objective-c cocos2d-iphone
我希望使用cocos2d在iPhone应用程序中持续显示游戏分数.关闭cocos2d显示应用程序运行的FPS的代码:
-(void) showFPS
{
frames++;
accumDt += dt;
if ( accumDt > 0.1) {
frameRate = frames/accumDt;
frames = 0;
accumDt = 0;
}
NSString *str = [NSString stringWithFormat:@"%.1f",frameRate];
[FPSLabel setString:str];
[FPSLabel draw];
}
Run Code Online (Sandbox Code Playgroud)
我可以得到正确显示的分数,但它闪烁,即使应用程序以更快的速度运行60 FPS ...任何想法?
对于任何可能感兴趣的人,我最终使用cocos2d标签:
scoreLabel = [Label labelWithString: [NSString stringWithFormat:@"%d", score] dimensions: CGSizeMake(180, 20) alignment: UITextAlignmentRight fontName:@"Arial" fontSize: 20];
[scoreLabel setPosition: cpv(100,100)];
[self add: scoreLabel];
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助别人.