Saturday, January 6, 2024
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 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 from SKEffectNode. Be sure that to allow filters by setting shouldEnableEffects = 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?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments