【问题标题】:Getting SpriteKit statistics similar to SceneKit's showsStatistics获取类似于 SceneKit 的 showStatistics 的 SpriteKit 统计信息
【发布时间】:2020-09-23 06:37:42
【问题描述】:

我正在开发一款 SpriteKit 游戏,并想稍微介绍一下它。 SceneKit 在 SCNView 上有一个非常有用的 showsStatistics 属性,当它展开时会显示这个图表:

如何获取 SpriteKit 游戏的每帧统计信息?对Instruments了解的不够深入,但据我所知,Time Profiler模板只显示累计函数时间,Game Performance模板只显示Metal的渲染时间。

非常感谢。

【问题讨论】:

    标签: ios swift sprite-kit instruments mac-catalyst


    【解决方案1】:

    我发现路标功能对此很有用。

    logging.swift:

    import Foundation
    import os.log
    
    extension OSLog {
      static var subsystem = Bundle.main.bundleIdentifier!
      static let poi = OSLog(subsystem: subsystem, category: .pointsOfInterest)
    }
    

    那么对于场景:

    class MyScene: SKScene {
      let signpostID = OSSignpostID(log: .poi)
    
      override func update(_ currentTime: TimeInterval) {
        os_signpost(.begin, log: .poi, name: "1_update", signpostID: signpostID)
        // update code here
        endOfUpdate()
      }
    
      /// Mark the end of the update phase and the start of actions
      func endOfUpdate() {
        os_signpost(.end, log: .poi, name: "1_update", signpostID: signpostID)
        os_signpost(.begin, log: .poi, name: "2_actions", signpostID: signpostID)
      }
    
      /// Mark the end of actions and the start of physics computations
      override func didEvaluateActions() {
        os_signpost(.end, log: .poi, name: "2_actions", signpostID: signpostID)
        os_signpost(.begin, log: .poi, name: "3_physics", signpostID: signpostID)
      }
    
      /// Mark the end of the render loop
      override func didFinishUpdate() {
        os_signpost(.end, log: .poi, name: "3_physics", signpostID: signpostID)
      }
    }
    

    然后使用兴趣点工具;我通常会将其添加到游戏性能配置文件中。您将为渲染循环的每个阶段标记出区域。 (我从未使用过约束,因此更新的结束和物理模拟的结束在我的情况下是重合的,上面没有标记,但如果你需要捕获更多,你可以覆盖 didSimulatePhysicsdidApplyConstraints那里有详细信息。请参阅https://developer.apple.com/documentation/spritekit/skscene/responding_to_frame-cycle_events 处的渲染循环描述)

    您还可以在适当的位置添加其他路标。我将它们用于标记各种游戏事件(例如,敌人生成、玩家被击中等)并标记我怀疑对性能很重要的代码部分的开始/结束。以窗口模式在仪器下运行,到达游戏有一些滞后问题的地步,然后停止跟踪。您可以查看跟踪以了解发生了什么。

    【讨论】:

    • 这太棒了,非常感谢。我通过调用 super in-between 将大量路标放入场景的子类中,现在可以轻松地将我的场景加载为这种类型以进行分析。
    猜你喜欢
    • 2011-08-24
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多