如何使用 Sprite Kit 逐渐模糊 SKSpriteNode 的图像? [英] How to progressively blur a SKSpriteNode's image using Sprite Kit?

查看:75
本文介绍了如何使用 Sprite Kit 逐渐模糊 SKSpriteNode 的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以举例说明如何使用 Apple 的 Sprite Kit 逐步模糊 SKSpriteNode 的图像吗?例如,假设用户触摸屏幕上的按钮,然后触发背景缓慢(即逐渐)模糊,直到达到特定阈值.理想情况下,我也想反转这个过程(例如,允许用户通过触摸相同的按钮来取消模糊图像).

Can someone provide an example of how to progressively blur a SKSpriteNode's image using Apple's Sprite Kit? For instance, let's say the user touches a button on the screen which will then trigger the background to slowly (i.e. progressively) blur until it reaches a specific threshold. Ideally, I would like to reverse the process too (e.g. allow the user to unblur the image by touching the same button).

推荐答案

有两种可能的途径来解决这个问题,都使用 SKEffectNodes

There are two possible paths to take on this, both use SKEffectNodes

SKEffectNodes 允许您将 CI 过滤器应用于节点.

SKEffectNodes allow you to apply CI Filters to a node.

高斯模糊有一个 CI 过滤器.所以创建一个SKEffectNode,并为其分配一个模糊滤镜,然后将按钮添加为子项.

There is a CI Filter for Gaussian Blur. So Create a SKEffectNode, and assign it a blur filter, then add the button as a child.

你是如何制作动画的?

使用 SKAction 创建自定义动作,并更改过滤器的参数,但是,这可能很慢,并且并不总是提供您可能期望的渐进式"模糊效果,所以我要做的是:

Use SKAction to create a custom action, and change the parameters of filter, however, this can be slow and doesn't always give the 'progressive' blur effect you might expect, so what I do is this:

我像上面描述的那样创建了一个过滤器和 SKEffectNode,然后我使用 SKView.textureForNode 将结果渲染到一个纹理.然后我将生成的纹理添加到一个数组中,之后我循环这个,继续在创建的前一个图像之上应用模糊效果,直到我有一定数量的帧.然后使用创建的纹理通过 SKAction.animateWithTextures 制作动画.根据我的经验,结果非常好.

I create a filter and SKEffectNode like described above, then I render the result to a Texture, using SKView.textureForNode. I then add the resulting texture to an array, after that I loop this, continuinng to apply the blur effect on top of the previous image created, until I have a set number of frames. Then use the textures created to make an animation with SKAction.animateWithTextures. In my experience, this comes out very nicely.

这篇关于如何使用 Sprite Kit 逐渐模糊 SKSpriteNode 的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆