小编App*_*per的帖子

游戏中心格式化时间

您为scoreReporter设置的值是什么,以便在游戏中心排行榜中显示为正确的时间.您需要什么来隐藏在排行榜中正确显示的秒数.任何帮助将不胜感激.

这是我的代码:

GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"BestTime"] autorelease];
scoreReporter.value = TotalSeconds * 10;
Run Code Online (Sandbox Code Playgroud)

ios game-center gkscore

6
推荐指数
1
解决办法
1657
查看次数

NSTimer越来越快

我试图使用计时器来跟踪游戏中的时间.这是计时器的代码.为什么每次我从主菜单重新启动游戏时计时器几乎快两倍.是因为我在退出之前没有使计时器失效.我试图使计时器无效,但它只是给出错误exc_bad访问权限

-(void) StartTimer {
   TotalSeconds = 0;
   GameCenterTotalSeconds = 0;
   timeSec = 0;
   timeMin = 0;
   timer = [[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES]retain];
   //[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}

//Event called every time the NSTimer ticks.
- (void)timerTick:(NSTimer*) timer {        
TotalSeconds++;
    GameCenterTotalSeconds= GameCenterTotalSeconds + .1;
    timeSec = timeSec + .1;
    if (timeSec >= 60)
    {
        timeSec = 00;
        timeMin++;
    }
    //Format the string 00:00
    NSString* timeNow = [NSString stringWithFormat:@"Time: %02d:%.1f", timeMin, timeSec];
    //Display on your label
    timeLabel.text = timeNow;
} …
Run Code Online (Sandbox Code Playgroud)

objective-c nstimer

2
推荐指数
1
解决办法
1140
查看次数

标签 统计

game-center ×1

gkscore ×1

ios ×1

nstimer ×1

objective-c ×1