我在spritebuilder中玩游戏,我试图每隔0.005秒移动一次球。我有NSTimer
这样做,但有时ball.position.y + 2
是不同的。
例如,有一次我玩游戏时,球会以我想要的速度移动到屏幕顶部。然后,在没有关闭游戏的情况下,只是再次打开场景,球以一半的速度移动,好像+ 2
当时没有那么多,或者NSTimer
决定以半速跑。
注意:这仅发生在实际设备上。我无法在模拟器中实现它。
有谁知道为什么会这样?
感谢。
编辑:我的代码(删节):
timer2 = NSTimer.scheduledTimerWithTimeInterval(0.005, target: self, selector: "updateTick", userInfo: nil, repeats: true)
我的更新功能:
func updateTick() {
...
incrementBalls()
...
}
我的incrementBalls()
功能:
for index in 0...balls.count - 1 {
balls[index].position = ccpAdd(_physicsBody.position, CGPoint(x: balls[index].position.x, y: balls[index].position.y + 2))
}
答案 0 :(得分:0)
我修改了这个,而是使用更新方法并进行一些数学计算来移动球而不是不可靠的NSTimer。