如何将CIPixellate Core Image Filter添加到Sprite Kit场景? [英] How do you add a CIPixellate Core Image Filter to a Sprite Kit scene?

查看:104
本文介绍了如何将CIPixellate Core Image Filter添加到Sprite Kit场景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将CIPixellate Core Image Filter添加到Sprite Kit场景?

How do you add a CIPixellate Core Image Filter to a Sprite Kit scene?

我有一个SpriteKit场景,它是SKScene或它的子类。
我想向场景添加Core Image滤镜。特别是CIPixellate过滤器,因此我可以免费拥有8位游戏天堂。

I have a SpriteKit scene that is an SKScene or subclass of it. I want to add a Core Image filter to the scene. Specifically a CIPixellate filter, so I can have 8-bit game heaven for free.

我该怎么做?

推荐答案

事实证明,这一点都不难。只是 Core Image Filter 文档过时且笨拙,而对于 SpriteKit 而言,这些文档完全是误导或不完整的,包括 SKEffectNode 文档。
SKEffectNode 文档在 SKEffectNode filter 属性上有此要求(截至本文):

It turns out this is not hard at all. It's just that the Core Image Filter docs are OLD and crufty and in the case of SpriteKit, the docs are flat out misleading or incomplete, including the SKEffectNode docs. The SKEffectNode docs have this to say (as of this post) on the filter property of SKEffectNode:


Core Image过滤器必须具有单个inputImage参数并产生单个outputImage参数。缺省值为nil。如果
的值为nil且启用了效果节点,则不会进行任何过滤来代替
。但是,它的子代仍会以单独的方式渲染,并且
会混合到父代的帧缓冲区中。

这是一种有用的信息,但不是十分有用的信息,因为Core Image Filter目录说CIP​​ixellate具有以下参数键:
inputImage
inputCenter
inputScale

它没有说出outputImage,也没有说inputScale是如何像素化的。

Well that's sort of informative, but not terribly informative, because the Core Image Filter catalog says CIPixellate has the following keys for parameters: inputImage inputCenter inputScale It doesn't say anything about an outputImage or that the inputScale is "how pixellated".

好吧,那就是……让我们看看如何做。

Well, that's that... let's look at how to.

首先,请注意 SKScene 继承自 SKEffectNode
这意味着您可以向其中添加CIFilters。很棒。

First off, note that SKScene inherits from SKEffectNode. That means you can add CIFilters to it. Awesome.

您需要做的就是这个。

首先创建一个CIFilter。

First create a CIFilter.

CIFilter *pixellateFilter;
pixellateFilter = [CIFilter filterWithName:@"CIPixellate"];
[pixellateFilter setDefaults]; // Remember to setDefaults...
// We could change some value but for this one we won't.
//  [pixellateFilter setValue:@(10.0) forKey:@"inputScale"];

然后将SKEffectNode配置为实际渲染效果!。

Then configure your SKEffectNode to actually render effects!.

[aScene setShouldEnableEffects:YES];

将过滤器居中并不是一个坏主意。

It's not a bad idea to center the filter. But your mileage may vary.

[aScene setShouldCenterFilter:YES];

下一步添加过滤器。

[aScene setFilter:pixellateFilter];

请注意,可以在将其添加到父节点之前或之后,之前或之后添加在屏幕上。您甚至可以构建自定义SKAction来执行此操作...:)

Note that you can add this before or after it is added to a parent node and before or after it is on screen. You can even build custom SKActions to do this... :)

从所有这一切中,您可以注意到的一件事是,Core Image Filter目录与是的,确实告诉您各种过滤器是各种CICategory类型的成员,即使这些过滤器的文档记录也很差。但您基本上可以假设,在给定类别中起作用的任何事物都意味着该类别中的其他过滤器也可能起作用:)

From all of this, one thing you can note is that the Core Image Filter catalog, as old as it is, does tell you that various filters are members of various CICategory types, even though those are poorly documented as well. But you can basically assume that anything that works in a given category implies that other filters in that category might also work :)

这篇关于如何将CIPixellate Core Image Filter添加到Sprite Kit场景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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