Created
January 29, 2016 12:03
-
-
Save lucasprag/48f8257e86791033cd85 to your computer and use it in GitHub Desktop.
The power of the physics body
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 { | |
// omitted | |
func setupPlayer() { | |
// omitted | |
// we create a physics body with the size of the player | |
player.physicsBody = SKPhysicsBody(rectangleOfSize: player.size) | |
// yes, it's that simple to be affected by gravity | |
player.physicsBody?.affectedByGravity = true | |
// make the player collide with the floor | |
player.physicsBody?.categoryBitMask = Physics.Character | |
player.physicsBody?.collisionBitMask = Physics.Character | |
// this add the player to the scene in order to appear in the screen | |
addChild(player) | |
} | |
func setupFloor() { | |
// omitted | |
// we create a physics body with the size of the floor | |
floor.physicsBody = SKPhysicsBody(rectangleOfSize: floor.size) | |
// the floor doesn't move, right? =) | |
floor.physicsBody?.affectedByGravity = false | |
// make the floor collide with the player | |
floor.physicsBody?.categoryBitMask = Physics.Character | |
floor.physicsBody?.collisionBitMask = Physics.Floor | |
// this add the floor to the scene in order to appear in the screen | |
addChild(floor) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment