Skip to content

Instantly share code, notes, and snippets.

@lucasprag
Last active January 29, 2016 19:23
Show Gist options
  • Save lucasprag/104ac3c454c1f864841b to your computer and use it in GitHub Desktop.
Save lucasprag/104ac3c454c1f864841b to your computer and use it in GitHub Desktop.
SKPhysicsContactDelegate
// omitted
class GameScene: SKScene, SKPhysicsContactDelegate {
// omitted
override func didMoveToView(view: SKView) {
// tell the physics world that the class the implements
// the SKPhysicsContactDelegate is the GameScene
physicsWorld.contactDelegate = self
setupFloor()
setupPlayer()
}
func setupPlayer() {
// omitted
// notify when the player collides
player.physicsBody?.contactTestBitMask = Physics.Character
// this add the player to the scene in order to appear in the screen
addChild(player)
}
func setupFloor() {
// omitted
// notify then the floor collides
floor.physicsBody?.collisionBitMask = Physics.Floor
// this add the floor to the scene in order to appear in the screen
addChild(floor)
}
func spawEnemy(){
// omitted
// notify when the enemy collides
enemy.physicsBody?.contactTestBitMask = Physics.Character
// add the enemy to the scene
addChild(enemy)
// store the enemy to use later
enemies.append(enemy)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment