3

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!

Nurassyl Nuridin
  • 444
  • 4
  • 13

1 Answers1

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:

mask

Whirlwind
  • 14,286
  • 11
  • 68
  • 157
  • 1
    Thanks for answer, @Whirlwind. But, I give my answer not correctly, because of my english), unfortunately. I wanted to say vise versa, want to crop SKShapeNode with SKLabelNode. For example there is a rectangle, and I add to it a SKLabelNode, but I want this shape cropped with label, so the background color have to show through this shape. Hope I explained clear) – Nurassyl Nuridin Mar 15 '16 at 07:40