I am building my first sprite kit game, and recently read an article that said to use SKTextureAtlas to improve performance.
So I migrated all my sprite images into organized
let textureAtlas = SKTextureAtlas(named: "player-iphone")
let playerFlyingTexture = textureAtlas.textureNamed("player-flying")
let player = Player(texture: playerFlyingTexture, color: UIColor.clearColor(), size: CGSizeMake(100.0, 100.0))
let physicsBody = SKPhysicsBody(texture: playerFlyingTexture, size: CGSizeMake(100.0, 100.0))
physicsBody.dynamic = true
physicsBody.affectedByGravity = true
physicsBody.usesPreciseCollisionDetection = false
physicsBody.categoryBitMask = CollisionCategories.Player
physicsBody.contactTestBitMask = CollisionCategories.Enemy
physicsBody.collisionBitMask = CollisionCategories.EdgeBody
physicsBody.allowsRotation = false
player.physicsBody = physicsBody
(credit goes to @Whirlwind for the help)
So for me, the fix ended up being that I need to change this:
let physicsBody = SKPhysicsBody(texture: self.texture, size: self.size)
let physicsBody = SKPhysicsBody(texture: self.texture, alphaThreshold: 0.3, size: self.size)
Apparently, the SKTextureAtlas cropping method used when generating a physics body has issues figuring out exactly what to crop, so setting the alphaThreshold explicitly seemed to fix it.
Obviously, that value will rely on your own image and what kind of transparency you have. But if you have hard edges like I did, you should be able to set that to some arbitrary value and be good to go.