I am working on a Flappy Bird clone. I'm running into a bug where my ground nodes disappear when I switch from portrait mode to landscape mode.
EDIT: I am basing my code off this: https://github.com/fullstackio/FlappySwift
As you can see, Kirby acts like the bottom is the ground, so it's clear that the node is there, it just cannot be seen. Here's the relevant code:
override func didMoveToView(view: SKView) {
...
backgroundScrollUpdate()
...
}
func backgroundScrollUpdate() {
...
let groundTexture = SKTexture(imageNamed: "Ground")
groundTexture.filteringMode = SKTextureFilteringMode.Nearest
let moveGroundDur = 0.02 * groundTexture.size().width*2
let moveGroundSprite = SKAction.moveByX(-groundTexture.size().width*2, y:0, duration:NSTimeInterval(moveGroundDur))
let resetGroundSprite = SKAction.moveByX(groundTexture.size().width*2, y:0, duration:0)
let moveGroundSpriteForever = SKAction.repeatActionForever(SKAction.sequence([moveGroundSprite, resetGroundSprite]))
// ground
for var i:CGFloat = 0; i < 2 + self.frame.size.width / (groundTexture.size().width*2); ++i {
let groundSprite = SKSpriteNode(texture: groundTexture)
groundSprite.setScale(2.0)
groundSprite.position = CGPointMake(i * groundSprite.size.width, groundSprite.size.height / 2)
groundSprite.runAction(moveGroundSpriteForever)
moving!.addChild(groundSprite)
}
// ground physics
let dummyGround = SKNode()
dummyGround.position = CGPointMake(0, groundTexture.size().height)
dummyGround.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(self.frame.size.width, groundTexture.size().height*2))
dummyGround.physicsBody?.dynamic = false
dummyGround.physicsBody?.categoryBitMask = worldCategory
self.addChild(dummyGround)
...
}
Thanks in advance.