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:
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 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!