2

All right, so let's say I have two SKShapeNodes (or any SKNode related object), one is a circle, and the other is a square. I'm just trying to put the square inside the circle so it looks like this:

How it should look

However, if I simply add the Square Shape Node inside the Circle Shape Node, as it's child, it just ends up looking like this:

How it actually looks

How do I limit the Circle's children to the circle's bounds? For those images, I basically created a new project with the default GameKit template, and it's GameScene.swift code is basically this:

import SpriteKit
import GameplayKit

class GameScene: SKScene {

    var circleNode = SKShapeNode()
    var squareNode = SKShapeNode()

    override func didMove(to view: SKView) {

        // Setup Shape Nodes:
        circleNode = SKShapeNode(circleOfRadius: 100)
        circleNode.fillColor = .blue
        squareNode = SKShapeNode(rectOf: CGSize(width: 200, height: 200))
        squareNode.fillColor = UIColor.gray.withAlphaComponent(0.5)

        // Positioning Shape Nodes:
        circleNode.position = CGPoint(x: 0, y: 0)
        squareNode.position = CGPoint(x: 0, y: -circleNode.frame.height/2) // At the middle of Circle Node!

        // Inserting Circle Node in the Game Scene:
        self.addChild(circleNode)

        // Inserting Square Shape Node in the Circle Node:
        circleNode.addChild(squareNode)
    }
}

How can I accomplish this behavior? Any help would be greatly appreciated!

ThiagoAM
  • 1,432
  • 13
  • 20
  • 1
    Have you tried SKCropNode ? It may allow you to obtain this kind of result (although the documentation seems to require a texture at some point). – Alain T. May 23 '17 at 13:35
  • cropnode will work for this. you can get a texture from a cgpath or even the whole object. – Fluidity May 25 '17 at 01:16

0 Answers0