我有一个移动的黑色图像在一个黑暗的屏幕上,使它更容易看到,我想添加一个白色的发光图像。这是我的移动图像代码:
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)我不知道如何或如何添加一个辉光,如果你需要更多的信息,请问。
发布于 2016-11-01 15:08:52
我创建这个扩展是为了向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()

发布于 2018-04-27 23:47:24
为此,您可以在任何类型的SKNode上执行此操作,方法是首先使用SKView实例上可用的纹理(from:SKNode)方法呈现其内容。
示例:
extension SKNode
{
func addGlow(radius:CGFloat=30)
{
let view = SKView()
let effectNode = SKEffectNode()
let texture = view.texture(from: self)
effectNode.shouldRasterize = true
effectNode.filter = CIFilter(name: "CIGaussianBlur",withInputParameters: ["inputRadius":radius])
addChild(effectNode)
effectNode.addChild(SKSpriteNode(texture: texture))
}
}https://stackoverflow.com/questions/40362204
复制相似问题