我正在研究 Flappy Bird 克隆。我遇到了一个错误,当我从纵向模式切换到横向模式时,我的地面节点会消失。
编辑:我的代码基于此:https ://github.com/fullstackio/FlappySwift
正如你所看到的,Kirby 的行为就像底部是地面,所以很明显节点在那里,只是看不到。以下是相关代码:
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)
...
}
提前致谢。