I use SKNode\'s xScale property to flip my sprites horizontally. Now, after updating iOS to version 7.1 horizontal flip causes my objects to sink inside the ground. (See ani
Alternative Solution
In my case I generally subclass SKSpriteNode to represent nodes in my scene and then encapsulate their behaviour (animation and movement) in the subclass. The Wrap sprite in container node solution doesn't work in my case as I have actions that animate the sprites texture and also move the sprite in sequence.
For example:
class Player: SKSpriteNode{
override init() {
...
super.init(texture: texture, color: nil, size: texture.size())
physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(70,75))
}
func attack(){
let action = SKAction.sequence([
SKAction.moveTo(enemyPosition, duration: 0),
SKAction.animateWithTextures(frames, timePerFrame: 0.5)
])
runAction(action)
}
}
Workaround
In my case I solved this by adding these methods to my 'Player' class:
class Player: SKSpriteNode{
private var flipped: Bool
...
func flip(){
flipped = !flipped
position = CGPointMake(-position.x, position.y)
}
//MARK: Workaround for iOS7 -xScale physics bugs
func willSimulatePhysics(){
xScale = 1
}
func didSimulatePhysics(){
xScale = flipped ? -1 : 1
}
}
And then override SKScene methods:
class MyScene: SKScene{
...
override func update(currentTime: CFTimeInterval) {
super.update(currentTime)
player.willSimulatePhysics()
}
override func didSimulatePhysics() {
super.didSimulatePhysics()
player.didSimulatePhysics()
}
}
This works because the node flip is disabled just before physics are simulated for the scene. The node flip is then applied just before the frame is rendered.