Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKEffectNode to an SKTexture?

SKEffectionNodes have a shouldRasterise "switch" that bakes them into a bitmap, and doesn't update them until such time as the underlying nodes that are impacted by the effect are changed.

However I can't find a way to create an SKTexture from this rasterised "image".

Is it possible to get a SKTexture from a SKEffectNode?

like image 733
Confused Avatar asked Mar 29 '26 18:03

Confused


1 Answers

I think you could try a code like this (it's just an example):

if let effect = SKEffectNode.init(fileNamed: "myeffect") {
    effect.shouldRasterize = true
    self.addChild(effect)   
    ...         
    let texture = SKView().texture(from: self)
}

Update:

After you answer, hope I understood better what do you want to achieve.

This is my point of view: if you want to make a shadow of a texture, you could simply create an SKSpriteNode with this texture:

let shadow = SKSpriteNode.init(texture: <yourTexture>)
shadow.blendMode = SKBlendMode.alpha
shadow.colorBlendFactor = 1
shadow.color = SKColor.black
shadow.alpha = 0.25

What I want to say is that you could proceed step by step:

  • get your texture
  • elaborate your texture (add filters, make some other effect..)
  • get shadow

This way of working produces a series of useful methods you could use in your project to build other kind of elements. Maybe, by separating the tasks you don't need to use texture(from:)

like image 187
Alessandro Ornano Avatar answered Apr 02 '26 02:04

Alessandro Ornano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!