0
das ist meine erste Frage hier so - Hallo Wort.Wie auf touch.location zu zwingen, nur an einem bestimmten Ort auf dem Bildschirm zu arbeiten?
Ich habe ein kleines Problem mit meinem Code. Ich möchte auf dieses Programm zwingen, Bälle nur erscheinen zu lassen, wenn Sie berühren und gleich y: 650 Punkte und Kästchen erscheinen nur, wenn Sie unter y: 650 Punkt berühren werden. x Position macht hier keine Rolle.
Das ist mein Code:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let location = touch.location(in: self)
let objects = nodes(at: location)
if objects.contains(editLabel) {
editingMode = !editingMode
} else {
if editingMode {
let size = CGSize(width: GKRandomDistribution(lowestValue: 16, highestValue: 128).nextInt(), height: 16)
let box = SKSpriteNode(color: RandomColor(), size: size)
box.zRotation = RandomCGFloat(min: 0, max: 3)
box.position = location
box.physicsBody = SKPhysicsBody(rectangleOf: box.size)
box.physicsBody!.isDynamic = false
addChild(box)
} else {
let ball = SKSpriteNode(imageNamed: "ballRed")
ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.size.width/2.0)
ball.physicsBody!.contactTestBitMask = ball.physicsBody!.collisionBitMask
ball.physicsBody!.restitution = 0.4
ball.position = location
ball.name = "ball"
addChild(ball)
}
}
}
}
Wir freuen uns für Hilfe :)
Sie 'in y' Wert des' location' verwenden können Ihre if-Aussagen. –