【问题标题】:Render SKScene to SKTexture?将 SKScene 渲染到 SKTexture?
【发布时间】:2023-04-05 11:43:01
【问题描述】:

Sprite Kit 中有没有一种方法可以将屏幕(所有当前的SKScene 渲染节点)捕获到SKTexture,以便我可以应用 CIFilter,然后将 SKTexture 分配回新的SKSpriteNode ?

我知道我可以设置一个SKEffectNode,作为我的节点树的父级,应用过滤器等并以这种方式获得结果,但我真的需要一个 过滤 SKTexture (或SKSpriteNode)我以后可以重复使用吗?

编辑:

可能的解决方案:

textureFromNode:
Renders and returns a Sprite Kit texture that contains the node’s contents.

是的,有效:

   SKTexture *texture = [[self view] textureFromNode:[self scene]];
   [blurSprite setTexture:texture];

【问题讨论】:

  • 请在单独的答案中写下您的解决方案,并将其标记为已接受的答案。这样其他人更容易找到。

标签: ios sprite-kit sktexture skeffectnode


【解决方案1】:

来自 Apple 文档:

textureFromNode:渲染并返回一个 Sprite Kit 纹理 包含节点的内容。

代码示例:

   SKTexture *texture = [[self view] textureFromNode:[self scene]];
   [blurSprite setTexture:texture];

【讨论】:

    【解决方案2】:

    您应该尝试使用来自UIViewsnapshotViewAfterScreenUpdates: 方法。

    您的SKScene 位于具有此方法的SKView 中。

    之后,您可以从视图中提取图像,并使用它创建一个SKNode

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      • 2017-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      相关资源
      最近更新 更多