gpt4 book ai didi

ios - 节点从纵向模式消失到横向模式(Sprite Kit | Swift | Flappy Bird)

转载 作者:行者123 更新时间:2023-11-28 11:19:36 27 4
gpt4 key购买 nike

我正在制作 Flappy Bird 的克隆版。当我从纵向模式切换到横向模式时,我遇到了一个错误,即我的地面节点消失了。

编辑:我的代码基于此:https://github.com/fullstackio/FlappySwift

Portrait mode

Landscape mode

如您所见,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)
...
}

提前致谢。

最佳答案

当旋转到横向时,框架大小不会改变。 (例如,在移动到横向后它仍然是 768x1024 而不是 1024x768)。

您需要使用“边界”而不是“框架”来放置地面。照原样,你把它放在底部。地面就在那里,你只是看不到它;)

self.view.bounds

例如:iOS UIView get frame after rotation

例如:"Incorrect" frame / window size after re-orientation in iPhone

最佳链接: How to get orientation-dependent height and width of the screen?

关于ios - 节点从纵向模式消失到横向模式(Sprite Kit | Swift | Flappy Bird),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29497272/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com