我目前正在使用SKShapeNode
andSKCropNode
在节点内创建孔。但是,我希望能够在其中创建自定义形状的孔。当我尝试用 maskNode 属性内的自定义图像替换圆形孔时SKCropNode
,我得到相反的结果。
这就是我想要实现的目标:
这是我目前拥有的代码:
let radius = 200
let fullScreen: SKSpriteNode = SKSpriteNode(texture: nil, color: backgroundColor, size: CGSize(width: frame.size.width, height: frame.size.height))
let mask: SKSpriteNode = SKSpriteNode(texture: nil, color: .white, size: CGSize(width: frame.size.width, height: frame.size.height))
let circle: SKShapeNode = SKShapeNode(circleOfRadius: radius)
let crop: SKCropNode = SKCropNode()
fullScreen.position = .zero
fullScreen.alpha = 1
fullScreen.zPosition = 0
mask.position = .zero
mask.alpha = 1
circle.fillColor = .red
circle.lineWidth = 4
circle.alpha = 0.001
circle.blendMode = .replace
circle.position = CGPoint(x: 0, y: -100)
mask.addChild(circle)
crop.maskNode = mask
crop.name = "nodeWithHole"
crop.addChild(fullScreen)
addChild(crop)
这可以通过 SpriteKit 实现吗?