Making SKLabelNode as a crop node of SKShapeNode

对着背影说爱祢 提交于 2019-12-08 00:12:14

问题


Can't find in web, how to make SKLabelNode cropping SKShapeNode. When i colorize the background, my goal is colorize the label too with the same method, so both of them have to colorize simultaneously. But can't imagine how to crop SKShapeNode with this label. Help me please!


回答1:


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

If I understand you correctly, you can set SKLabelNode as a mask of a SKCropNode, like this:

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)

}

The result:



来源:https://stackoverflow.com/questions/35986345/making-sklabelnode-as-a-crop-node-of-skshapenode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!