Моя цель - выводить "hit" , но без изменения позиций card
и anotherCard
.Они должны касаться друг друга, но не двигаться.Однако didBegin не вызывается.
Структура:
struct physicBodyCharacters {
static let cardNumber = 00000001 //1
static let anotherCardNumber = 00000010 //2
static let nobodyNumber = 00000100 //4
}
в viewDidLoad ():
gameScene2.physicsWorld.gravity = CGVector(dx: 0, dy: -9.81)
gameScene2.physicsWorld.contactDelegate = self
Первый узел:
card = SKSpriteNode(texture: cardTexture)
card.position = CGPoint(x: gameScene2.size.width / 2 + 150, y: 95)
card.zPosition = 3
card.setScale(1)
card.physicsBody = SKPhysicsBody(texture: cardTexture, size: card.size)
card.physicsBody?.affectedByGravity = false
card.physicsBody?.categoryBitMask = UInt32(physicBodyCharacters.cardNumber)
card.physicsBody?.collisionBitMask = UInt32(physicBodyCharacters.nobodyNumber)
card.physicsBody?.contactTestBitMask = UInt32(physicBodyCharacters.anotherCardNumber)
ВторойУзел:
anotherCard = SKSpriteNode(texture: anotherCardTexture)
anotherCard.position = CGPoint(x: 31 , y: 532)
anotherCard.zPosition = 2
anotherCard.setScale(1)
anotherCard.physicsBody = SKPhysicsBody(texture: anotherCardTexture, size: battlefieldCard0.size)
anotherCard.physicsBody?.affectedByGravity = false
anotherCard.physicsBody?.categoryBitMask = UInt32(physicBodyCharacters.anotherCardNumber)
anotherCard.physicsBody?.collisionBitMask = UInt32(physicBodyCharacters.nobodyNumber)
anotherCard.physicsBody?.contactTestBitMask = UInt32(physicBodyCharacters.cardNumber)
didBegin () Функция:
func didBegin(_ contact: SKPhysicsContact) {
print("contact")
let contanctMask = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
switch contanctMask
{
case UInt32(physicBodyCharacters.cardNumber) | UInt32(physicBodyCharacters.anotherCardNumber):
print("hit")
default:
break
}
}
За каждый ответ я очень благодарен.