gpt4 book ai didi

ios - 为 SKSpriteNode 添加发光效果

转载 作者:IT王子 更新时间:2023-10-29 05:16:51 25 4
gpt4 key购买 nike

我在黑暗的屏幕上有一个移动的黑色图像,为了更容易看到我想在图像中添加白光。这是我的动态图像代码:

   Ghost = SKSpriteNode(imageNamed: "Ghost1")
Ghost.size = CGSize(width: 50, height: 50)
Ghost.position = CGPoint(x: self.frame.width / 2 - Ghost.frame.width, y: self.frame.height / 2)

Ghost.physicsBody = SKPhysicsBody(circleOfRadius: Ghost.frame.height / 1.4)
Ghost.physicsBody?.categoryBitMask = PhysicsCatagory.Ghost
Ghost.physicsBody?.collisionBitMask = PhysicsCatagory.Ground | PhysicsCatagory.Wall
Ghost.physicsBody?.contactTestBitMask = PhysicsCatagory.Ground | PhysicsCatagory.Wall | PhysicsCatagory.Score
Ghost.physicsBody?.affectedByGravity = false
Ghost.physicsBody?.isDynamic = true
Ghost.zPosition = 2

self.addChild(Ghost)

我不确定如何或使用什么来添加光晕,如果您需要更多信息,请询问。

最佳答案

我创建这个扩展是为了给 SKSpriteNode 添加发光效果

只需将其添加到您的项目中

extension SKSpriteNode {

func addGlow(radius: Float = 30) {
let effectNode = SKEffectNode()
effectNode.shouldRasterize = true
addChild(effectNode)
let effect = SKSpriteNode(texture: texture)
effect.color = self.color
effect.colorBlendFactor = 1
effectNode.addChild(effect)
effectNode.filter = CIFilter(name: "CIGaussianBlur", parameters: ["inputRadius":radius])
}
}

现在给定一个 SKSpriteNode

let sun = SKSpriteNode(imageNamed: "sun")

一切尽在掌握

sun.addGlow()

enter image description here

关于ios - 为 SKSpriteNode 添加发光效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40362204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com