gpt4 book ai didi

ios - Sprite 套件物理 : possible to use a fixed update?

转载 作者:可可西里 更新时间:2023-11-01 02:16:18 26 4
gpt4 key购买 nike

我有一个场景,我的场景中发生了固定更新。

每次更新,我都想使用 Sprite 以前的位置创建一个阴影。

func update(currentTime: NSTimeInterval)
{
shadow.position = sprite.position
}

现在,当我对 sprite 施加任何冲动时,我希望 sprite 递增相同的步数,而不管到达下一个更新帧实际使用了多少时间。

然而,事实并非如此,因为将我的模拟器上的阴影与我的设备上的阴影进行比较时,两者之间的距离非常不同。

E.G. It took my phone 1 second to move the sprite 60 steps It took my simulator 2 seconds to move the sprite 60 steps

In the fixed update world. both took 60 frames to achieve, the simulator just lagged.

The actual results however will put the simulator at 120 steps

我尝试在 SKView 上禁用asynchronous,希望这能让我得到固定的更新,但这让我无处可去,所以我想问是否有人知道如何获得 SKPhysics在一个固定的更新框架上工作。

最佳答案

我不确定它是否对你有用,我很确定你知道这个参数,但也许你没有注意到:

if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsPhysics = true
skView.showsNodeCount = true

skView.frameInterval = 1 // real devices
#if (arch(i386) || arch(x86_64)) && os(iOS)
skView.frameInterval = 2 // <- this one
#endif

/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .ResizeFill
skView.presentScene(scene)
}

来源:

    /* Number of hardware vsyncs between callbacks, same behaviour as CADisplayLink. Defaults to 1 (render every vsync) */
public var frameInterval: Int

文档:

这是苹果官方document说:

The default value is 1, which results in your game being notified at the refresh rate of the display. If the value is set to a value larger than 1, the display link notifies your game at a fraction of the native refresh rate. For example, setting the interval to 2 causes the scene to be called every other frame, providing half the frame rate.

Setting this value to less than 1 results in undefined behavior and is a programmer error.

关于ios - Sprite 套件物理 : possible to use a fixed update?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com