好吧,假设我有两个SKShapeNodes(或任何与SKNode相关的对象),一个是圆形,另一个是正方形。我只是想把方块放在圆圈内,所以它看起来像这样:
但是,如果我只是在Circle Shape Node中添加Square Shape Node,就像它的孩子一样,它最终看起来像这样:
如何将Circle的孩子限制在圆圈的范围内?对于那些图像,我基本上用默认的GameKit模板创建了一个新项目,它的GameScene.swift代码基本上是这样的:
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)
}
}
我该如何完成此行为?任何帮助将不胜感激!