Alternative solution
In my case, I usually subclass SKSpriteNode to represent the nodes in my scene, and then encapsulate their behavior (animation and movement) in a subclass. The wrap sprite in the node container solution does not work in my case, because I have actions that enliven the sprite 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) } }
Bypass
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) }
And then override the 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 flip node is disabled just before the physics is modeled for the scene. The node flag is then applied immediately before rendering the frame.
Imran
source share