I have been trying to do this for ages, what I would like to do is, I have a rocket and missiles coming down in my Scene and I want a very very simple explanation on how to do this so when the missiles collide with the rocket it will run a function in your code just call the function "func" and I am not very familiar with SKPhysicsBody and enums so please explain those as well please (This is in swift spriteKit). Thanks in Advance.
Asked
Active
Viewed 71 times
-2
-
Please post some code related to what you have already achieved – ZeMoon Feb 21 '15 at 11:44
-
I have not done anything yet but i have some tutorials do know any good ones? – Lucas Farleigh Feb 21 '15 at 11:51
1 Answers
0
I would comment but i don't have enough reputation XD. I have watched a tutorial on youtube that explains you how to remove with collision. https://www.youtube.com/watch?v=ylIIy5EbsWQ
func didBeginContact(contact: SKPhysicsContact!){
// Body1 and 2 depend on the categoryBitMask << 0 und << 1
var firstBody:SKPhysicsBody
var secondBody:SKPhysicsBody
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask){
firstBody = contact.bodyA
secondBody = contact.bodyB
}else{
firstBody = contact.bodyB
secondBody = contact.bodyA
}
torpedoDidCollideWithAlien(contact.bodyA.node as SKSpriteNode, alien: contact.bodyB.node as SKSpriteNode)
}
func torpedoDidCollideWithAlien(torpedo:SKSpriteNode, alien:SKSpriteNode){
println("HIT")
torpedo.removeFromParent()
alien.removeFromParent()
aliensDestroyed++
if (aliensDestroyed > 30){
var transition:SKTransition = SKTransition.flipHorizontalWithDuration(0.5)
var gameOverScene:SKScene = GameOverScene(size: self.size, won: true)
self.view.presentScene(gameOverScene, transition: transition)
}
}

Ma new L
- 29
- 1
- 9