限制Sprite Kit帧速率

3
我刚开始学习编程,并正在创建一个sprite kit游戏。我正在制作一个包含大型图像的滚动背景,这降低了帧率到30fps。然而,在游戏开始之前,没有其他精灵加入,帧率在30fps和60fps之间变化。由于我在更新方法中移动我的背景,因此背景滚动的速度不断变化。我希望将最大帧率限制为30fps以实现恒定速度。我也听说过使用Delta时间来实现恒定速度,但是无法在网上找到相关教程。
提前致谢。

3
你在测试设备上进行测试了吗?如果没有,请测试一下。模拟器性能完全不能代表真实设备的表现。 - CodeSmile
在设备上进行了测试。性能大大提升。谢谢。 - dev_cd123
2个回答

11
你可以通过将 frameInterval 设置为 2 来实现此目标,这将有效地将最大帧速率从 60 降低到 30。

6

frameInterval现在已经被废弃。

请将您的SKView对象的preferredFramesPerSecond属性设置为30。

例如(Swift 3.2):

// ViewController.swift

    import Cocoa
    import SpriteKit
    import GameplayKit

    class ViewController: NSViewController {

        @IBOutlet var skView: SKView!

        override func viewDidLoad() {
            super.viewDidLoad()

            if let view = self.skView {

                skView.preferredFramesPerSecond = 30//this will set framerate to 30

                // Load the SKScene from 'GameScene.sks'
                if let scene = SKScene(fileNamed: "GameScene") {
                    // Set the scale mode to scale to fit the window
                    scene.scaleMode = .aspectFill

                    // Present the scene
                    view.presentScene(scene)
                }

                view.ignoresSiblingOrder = true

                view.showsFPS = true
                view.showsNodeCount = true
            }
        }
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接