I can apply a Core Picture filter to a SpriteKit node by:
- Making the node a baby of an
SKEffectNode
- Making use of the filter to the
SKEffectNode
- Or within the case of the scene itself, apply the filter instantly, since
SKScene
inherits fromSKEffectNode
. Be sure that to allow filters by settingshouldEnableEffects = true
on the scene.
Nevertheless, I can solely apply one filter at a time. How do I chain filters? And the way do I management the order of their utility?
An identical query exists right here, however I do not perceive the reply. It assumes an excessive amount of implicit data.
Here’s what I’ve.
The bottom code that units the scene and creates a sprite node and an impact node:
override func didMove(to view: SKView) {
shouldEnableEffects = true // allows filtering of the scene itself
let mySprite = SKSpriteNode(imageNamed: "myImage")
let myEffectNode = SKEffectNode()
myEffectNode.addChild(mySprite)
addChild(myEffectNode)
}
I can apply a Core Picture filter like this:
override func didMove(to view: SKView) {
// earlier code
filter = CIFilter(identify: "CIMotionBlur") // filters the entire scene
myEffectNode.filter = CIFilter(identify: "CIMotionBlur") // filters the node
}
However I cannot chain or pile the filters like this:
myEffectNode.filter = CIFilter(identify: "CIMotionBlur")
myEffectNode.filter = CIFilter(identify: "CIPixellate", parameters: [
"inputScale": 8
])
// Solely the final known as filter is utilized
How do I apply a number of filters on the identical node? What are the coding patterns and constructions I want to know to take action?