0

Flappy Bird クローンに取り組んでいます。ポートレート モードからランドスケープ モードに切り替えると、グラウンド ノードが消えるというバグが発生しています。

編集:私はこれに基づいてコードを作成しています: https://github.com/fullstackio/FlappySwift

ポートレートモード

横長モード

ご覧のとおり、カービィは底が地面のように振る舞うので、ノードがそこにあることは明らかで、見えません。関連するコードは次のとおりです。

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)
   ...
}

前もって感謝します。

4

1 に答える 1