I am new to SpriteKit / Swift coding and have the following problem: It is assumed that the character collects coins by jumping into them. There is no problem in detecting a collision and getting rid of the collected coin, but my character bounces off the coin before it disappears.
The character must fly through the coin and collect it along the way.
let playerCategory: UInt32 = 0x1 << 0 let coinCategory: UInt32 = 0x1 << 1
player = SKSpriteNode(texture: playerTexture) player.physicsBody = SKPhysicsBody(circleOfRadius: player.size.height / 2) player.physicsBody?.dynamic = true player.physicsBody?.allowsRotation = false player.physicsBody?.categoryBitMask = playerCategory player.physicsBody?.contactTestBitMask = coinCategory var coin:SKSpriteNode = SKSpriteNode(texture: coinTexture) coin.physicsBody = SKPhysicsBody(circleOfRadius: coin.size.height / 2) coin.physicsBody?.dynamic = false coin.physicsBody?.allowsRotation = false coin.physicsBody?.categoryBitMask = coinCategory coin.physicsBody?.contactTestBitMask = playerCategory
func playerDidCollideWithCoin(player:SKSpriteNode, thisCoin:SKSpriteNode) { thisCoin.removeFromParent() coinsCollected++ }
Collision detection works like this, but, as I said, how can I avoid flying and replace it with βflyingβ?
I am using Xcode 6 Beta 7
Thanks in advance!
The solution is in the comments below;)
Mikeb source share