HomeiOS Developmentios - Apply a number of Core Picture filters to a SpriteKit...

ios – Apply a number of Core Picture filters to a SpriteKit node


I can apply a Core Picture filter to a SpriteKit node by:

  • Making the node a toddler of an SKEffectNode
  • Making use of the filter to the SKEffectNode
  • Or within the case of the scene itself, apply the filter immediately, since SKScene inherits from SKEffectNode. Make certain to allow filters by setting shouldEnableEffects = true on the scene.

Nonetheless, I can solely apply one filter at a time. How do I chain filters? And the way do I management the order of their software?

An identical query exists right here, however I do not perceive the reply. It assumes an excessive amount of implicit information.

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 // permits 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 can’t chain or pile the filters like this:

myEffectNode.filter = CIFilter(identify: "CIMotionBlur")
myEffectNode.filter = CIFilter(identify: "CIPixellate", parameters: [
    "inputScale": 8
])
// Solely the final referred to as filter is utilized

How do I apply a number of filters on the identical node? What are the coding patterns and buildings I want to know to take action?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments