SpriteKit - 如何渲染到现有纹理

SpriteKit - How to render to an existing texture

在 SpriteKit 中,如何将场景渲染到 现有 纹理?

SKView 中有这个方法 textureFromNode: 将场景渲染到纹理,但它正在创建一个新纹理。我想避免这种开销。

据我所知,没有这样的 API,这意味着您必须使用 SKMutableTexture 对象并使用 -modifyPixelDataWithBlock: 方法自行更新像素数据。

但是,这很可能比从您提到的 API 中获取新的 SKTexture 对象更昂贵。来自 SKMutableTexture documentation:

Normally, SpriteKit textures (SKTexture objects) are static, meaning that once created, their contents cannot be changed. This is important because a static image can be more efficiently managed inside the graphics hardware. However, sometimes you need to be able to update the contents of a texture dynamically. In this case, you should use a mutable texture. Because there is a performance penalty for updating the texture’s contents, consider other options first. For example, you can render a texture in hardware using the texture(from:) method and a node tree.

如果纹理创建实际上是通过检测可验证的瓶颈,您可能需要研究解决此问题的其他选项。