ユーザーが最初に触れる隅とユーザーが持ち上げるもう一方の隅に四角形を追加します。また、ユーザーが指をドラッグしている間に矩形が表示されるようにしたいと思います。すぐにスプライトキットを使用して角の四角形をタッチします。コードは実行されますが、矩形は表示されません
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let position1 = touch.location(in: self)
var x1 = position1.x
var y1 = position1.y
func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
let position2 = touch.location(in: self)
var x2 = position2.x
var y2 = position2.y
var originX = min(x1,x2)
var originY = min(y1,y2)
var cornerX = max(x1,x2)
var cornerY = max(y1,y2)
var rect_width = cornerX - originX
var rect_height = cornerY - originY
var rect_con = CGRect(x: originX, y:originY, width: rect_width, height: rect_height)
var box = SKShapeNode(rect: rect_con)
}
}