Draw a hole in a rectangle with SpriteKit?

后端 未结 1 1795
攒了一身酷
攒了一身酷 2020-12-09 23:01

How to draw a hole in a rectangle? I want to draw a rectangle which has a empty hole inside it and the background can be show.

I am using SKShapeNode to create a rec

相关标签:
1条回答
  • 2020-12-09 23:03

    Here's the code.

    import SpriteKit
    
    class GameScene: SKScene {
    
        override func didMove(to view: SKView) {
    
            let effect = SKEffectNode()
            addChild(effect)
    
            let rect = SKShapeNode(rect: CGRect(x: 0, y: 0, width: 400, height: 200))
            rect.fillColor = .green
            effect.addChild(rect)
    
    
            let hole = SKShapeNode(circleOfRadius: 40)
            hole.position = CGPoint(x: 200, y: 100)
            hole.fillColor = .white
            hole.blendMode = .subtract
            rect.addChild(hole)
    
        }
    }
    

    As you can see I create an SKEffectNode. Then I add to it the rectangle. Finally I add the hole to the rectangle.

    0 讨论(0)
提交回复
热议问题