gpt4 book ai didi

ios - 在 Sprite Kit 中混合颜色

转载 作者:行者123 更新时间:2023-11-29 10:24:12 24 4
gpt4 key购买 nike

我是 Sprite Kit 的新手,我想用它来实现一个简单的游戏。我想知道这在 Sprite Kit 中是否可行:

假设我画了两个圆圈,一个是红色,另一个是绿色。这两个圆圈之间有一个重叠区域,我希望这个区域的颜色可以自动设置为RED + Green = Yellow,有点像下图。

是否可以使用 Sprite Kit 来实现?如果可以,如何设置?

非常感谢任何回复!

enter image description here

最佳答案

你可以玩一个 blending mode连同SKEffectNode :

class GameScene:SKScene{

override func didMoveToView(view: SKView) {


let effect = SKEffectNode()

//Creating shapenodes
let shape1 = SKShapeNode(circleOfRadius: 50)
shape1.fillColor = SKColor.redColor()
shape1.strokeColor = SKColor.clearColor()
shape1.zPosition = 1
shape1.blendMode = SKBlendMode.Add

let shape2 = SKShapeNode(circleOfRadius: 50)
shape2.fillColor = SKColor.greenColor()
shape2.strokeColor = SKColor.clearColor()
shape2.zPosition = 2
shape2.blendMode = SKBlendMode.Add

let shape3 = SKShapeNode(circleOfRadius: 50)
shape3.fillColor = SKColor.blueColor()
shape3.strokeColor = SKColor.clearColor()
shape3.zPosition = 3
shape3.blendMode = SKBlendMode.Add


//Positioning
shape1.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame))

shape2.position = CGPoint(x: shape1.position.x - 25, y: shape1.position.y - 50)

shape3.position = CGPoint(x: shape1.position.x + 25, y: shape1.position.y - 50)

effect.addChild(shape1)
effect.addChild(shape2)
effect.addChild(shape3)

self.addChild(effect)

}
}

结果:

enter image description here

关于ios - 在 Sprite Kit 中混合颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33284020/

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