SKEffectNode to an SKTexture?

后端 未结 2 1729
礼貌的吻别
礼貌的吻别 2021-01-20 19:56

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 impa

2条回答
  •  一个人的身影
    2021-01-20 20:08

    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: )
    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:)

提交回复
热议问题