Last active
January 29, 2016 19:23
-
-
Save lucasprag/104ac3c454c1f864841b to your computer and use it in GitHub Desktop.
SKPhysicsContactDelegate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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