-1
私は現在ゲームを作っていて、画面の周りをドラッグできるスプライトを持っていますが、一度スプライトを移動させると、スプライトが手に入らず、ユーザのやりとりに反応しないようにします。 現在、これは私が解決策を見つけたスプライトのユーザインタラクションを無効にする
func 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
}
}
}
}
、それは次のようになります。ですから、ドラッグの開始されるであろう、それをタップすると、同じスプライト上の第2のタップは無視されるべきである一方で、それを周りにドラッグできるようにしたいですか?しかし、スプライトから指を離すまで、スプライトをドラッグすることはできますか? – Whirlwind
はい私が欲しいものを正確に – user2849178
[SpriteKitでワンタッチで複数のノードを一度に移動](http://stackoverflow.com/questions/41179326/moving-multiple-nodes-at-once-from-touch-with -spritekit) – Knight0fDragon