Search code examples
ios7swiftios8sprite-kitskphysicsbody

Swift physics not working on iOS7


I have a simple SpriteKit game that uses physics. Written in Swift, and works great in iOS8 Simulator. The node stops at the physicsworld edge.

But when running on iOS7 it falls right trough. Think it has something to do with the category, contact and collision bitmask.

any clue?

Defining the categories here

struct PhysicsCategory {
    static let None: UInt32 = 0
    static let Edge: UInt32 = 0b1 // 1
    static let Player: UInt32 = 0b10 // 2
    static let Enemy: UInt32 = 0b100 // 4
}

Setup World

physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
physicsWorld.contactDelegate = self
physicsBody!.categoryBitMask = PhysicsCategory.Edge
physicsWorld.gravity = CGVectorMake(0, -9.81)

Setup Player/Ball/Node

playerNode.physicsBody = SKPhysicsBody(polygonFromPath: path)
playerNode.physicsBody!.contactTestBitMask = PhysicsCategory.Player
playerNode.physicsBody!.dynamic = true
playerNode.physicsBody!.mass = 0.50
playerNode.physicsBody!.categoryBitMask = PhysicsCategory.Player
playerNode.physicsBody!.collisionBitMask = PhysicsCategory.Enemy | PhysicsCategory.Edge

Solution

  • Finally got it working!

    Updated to Yosemite 10.10.1 and Xcode 6.1.1, created a new project. Strange, but works great now.