gpt4 book ai didi

swift - 将 SKLabelNode 作为 SKShapeNode 的裁剪节点

转载 作者:可可西里 更新时间:2023-11-01 02:17:21 26 4
gpt4 key购买 nike

网上找不到,如何让SKLabelNode裁剪SKShapeNode。当我给背景上色时,我的目标是用同样的方法给标签上色,所以它们必须同时上色。但是无法想象如何用这个标签裁剪 SKShapeNode。请帮助我!

最佳答案

But can't imagine how to crop SKShapeNode with this label.

如果我没理解错的话,你可以将 SKLabelNode 设置为 SKCropNode 的掩码,如下所示:

override func didMoveToView(view: SKView) {

backgroundColor = .blackColor()

let cropNode = SKCropNode()
cropNode.position = CGPoint(x: frame.midX, y: frame.midY)
cropNode.zPosition = 1

let mask = SKLabelNode(fontNamed: "ArialMT")
mask.text = "MASK"
mask.fontColor = .greenColor()
mask.fontSize = 28

cropNode.maskNode = mask


let nodeToMask = SKSpriteNode(color: .purpleColor(), size: CGSize(width: 200, height: 200))
nodeToMask.position = CGPoint(x: 0, y: 0)
nodeToMask.name = "character"
cropNode.addChild(nodeToMask)
//Now colorize the sprite which acts like background
let colorize = SKAction.sequence([
SKAction.colorizeWithColor(.orangeColor(), colorBlendFactor: 0, duration: 1),
SKAction.colorizeWithColor(.purpleColor(), colorBlendFactor: 0, duration: 1)
])

nodeToMask.runAction(SKAction.repeatActionForever(colorize), withKey: "colorizing")

addChild(cropNode)

}

结果:

mask

关于swift - 将 SKLabelNode 作为 SKShapeNode 的裁剪节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35986345/

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