我已经弄清楚如何在单视图应用程序中制作计时器,但没有弄清楚 Spritekit。当我使用以下代码时,出现 2 个错误(如下所示)。谁能帮我解决这个问题吗?谢谢,杰克。
计时器。
if(!_scorelabel) {
_scorelabel = [SKLabelNode labelNodeWithFontNamed:@"Courier-Bold"];
_scorelabel.fontSize = 200;
_scorelabel.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
_scorelabel.fontColor = [SKColor colorWithHue: 0 saturation: 0 brightness: 1 alpha: .5];
[self addChild:_scorelabel];
}
_scorelabel = [NSTimer scheduledTimerWithTimeInterval: 1 target:self selector:@selector(Timercount)userInfo: nil repeats: YES];
错误
Incompatible pointer types assigned to 'SKLabelNode*' from 'NSTimer*'
Undeclared selector 'Timercount'
在 Swift 中可用:
在 Sprite Kit 中不要使用NSTimer, GCD or performSelector:afterDelay:
因为这些计时方法忽略节点、场景或视图的暂停状态。此外,您不知道它们在游戏循环的哪个点执行,这可能会导致各种问题,具体取决于您的代码实际执行的操作。
var actionwait = SKAction.waitForDuration(0.5)
var timesecond = Int()
var actionrun = SKAction.runBlock({
timescore++
timesecond++
if timesecond == 60 {timesecond = 0}
scoreLabel.text = "Score Time: \(timescore/60):\(timesecond)"
})
scoreLabel.runAction(SKAction.repeatActionForever(SKAction.sequence([actionwait,actionrun])))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)