Also mache ich gerade ein Spiel und ich habe ein Sprite, das über den Bildschirm gezogen werden kann, aber sobald ich das Sprite bewegen will ich das Sprite nicht mehr aufsprechen und nicht auf Benutzerinteraktion reagieren. Derzeit ist es das, was ichDeaktivierung der Benutzerinteraktion auf Sprites
versucht habenfunc addp1Cards() {
let player1 = Card(cardType: CardType(rawValue: player1_cards[p1int])!)
player1.size = CGSize(width: player1.size.width * 0.25, height: player1.size.height * 0.25)
player1.position = CGPoint(x: -10.4927577972412, y: 615.942138671875)
player1.zPosition = CGFloat(zpos)
player1.name = "\(player1_cards[0])"
print(player1_cards[0])
addChild(player1)
p1int += 1
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
print(location)
let rotR = SKAction.rotate(byAngle: 0.15, duration: 0.2)
let rotL = SKAction.rotate(byAngle: -0.15, duration: 0.2)
let cycle = SKAction.sequence([rotR, rotL, rotL, rotR])
let wiggle = SKAction.repeatForever(cycle)
if turnBool == true {
if let card = atPoint(location) as? Card {
card.zPosition = CardLevel.moving.rawValue
addp1Cards()
if touch.tapCount > 1 {
return
}
if card.enlarged { return }
card.run(wiggle, withKey: "wiggle")
card.removeAction(forKey: "drop")
card.run(SKAction.scale(to: 1.3, duration: 0.25), withKey: "pickup")
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
if let card = atPoint(location) as? Card {
if turnBool == true {
if card.enlarged { return }
card.position = location
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
if let card = atPoint(location) as? Card {
if turnBool == true {
turnBool = false
addp1Cards()
if card.enlarged { return }
card.zPosition = CardLevel.board.rawValue
card.removeAction(forKey: "wiggle")
card.run(SKAction.rotate(toAngle: 0, duration: 0.2), withKey:"rotate")
card.removeAction(forKey: "pickup")
card.run(SKAction.scale(to: 1.0, duration: 0.25), withKey: "drop")
card.removeFromParent()
addChild(card)
card.flip()
self.enumerateChildNodes(withName: "\(player2_cards[p2int - 2])") { card2y, stop in
card2y.isUserInteractionEnabled = false
}
}
}
}
So wollen Sie in der Lage sein, darauf tippen, das ein Anfang ziehen würde, und ziehen Sie sich um, während der zweite Hahn auf einem gleichen Sprit ignoriert werden soll? Aber Sie sollten immer noch in der Lage sein, das Sprite zu ziehen, bis Sie den Finger vom Sprite entfernen? – Whirlwind
Ja, das ist genau das, was ich will – user2849178
Mögliches Duplikat von [Mehrere Knoten gleichzeitig von Berührung mit SpriteKit verschieben] (http://stackoverflow.com/questions/41179326/moving-multiple-nodes-at-once-from-touch-with -spritekit) – Knight0fDragon