gpt4 book ai didi

ios - 使用 sprites velocity (swift) flappy bird 游戏旋转 Sprite

转载 作者:行者123 更新时间:2023-11-28 10:30:23 26 4
gpt4 key购买 nike

所以我正在学习如何使用 Sprite 来构建 iOS 游戏。我正在重新制作 flappy bird 作为我的第一个项目。我无法弄清楚如何正确工作的最后一段代码是鸟在空中落下时的旋转。

当我的鸟通过重力坠落时,它会俯冲下来,这很好。当我在点击屏幕时应用垂直脉冲时。这只鸟直接翻转 180 度,直接垂直看。这有点像我,但我如何平滑从 Nose 俯冲到垂直看的过渡?

bird.physicsBody?.allowsRotation = true
var velocityvector = bird.physicsBody?.velocity
let angle = atan2(velocityvector?.dy ?? 0, velocityvector?.dx ?? 0)
bird.zRotation = angle

这是我用来旋转小鸟的代码。

最佳答案

bird.physicsBody?.allowsRotation = true 
var velocityvector = bird.physicsBody?.velocity
let angle = atan2(velocityvector?.dy ?? 0, velocityvector?.dx ?? 0)
let rotateAction = SKAction.rotate(byAngle: angle, duration: 0.5)
// Or let rotateAction = SKAction.rotate(toAngle: angle, duration: 0.5)
bird.run(rotateAction)

关于ios - 使用 sprites velocity (swift) flappy bird 游戏旋转 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56431097/

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