我是Sprite Kit的新手,我想用它来实现一个简单的游戏。我想知道这是否可以在Sprite Kit中使用:
假设我画了两个圆圈,一个在红色,另一个在绿色。这两个圆圈之间有一个重叠区域,我希望这个区域的颜色可以自动设置为 RED + Green = Yellow ,有点像下图。
使用Sprite Kit是否可以这样做?如果有可能,如何设置?
非常感谢任何回复!
答案 0 :(得分:2)
您可以与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)
}
}
结果: