2015-10-22 54 views
1

我是Sprite Kit的新手,我想用它来实现一个简单的游戏。我想知道这是否可能在雪碧套件:Sprite Kit中的混色

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

使用Sprite Kit可以这样做吗?如果可能的话,如何设置它?

任何回复非常感谢!

enter image description here

回答

1

可以连同blending modeSKEffectNode

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

+0

这正是我想要的!谢谢! –

+0

还有一个问题。不是用纯色填充圆形,如果我填充了彩色纹理(例如带有红色和绿色图案的png图片),是否有无法达到类似的效果? –

+0

@HunTerDRF是的,你可以使用SKSpriteNode并用纹理初始化它。 – Whirlwind