使用精灵速度(快速)飞扬的鸟游戏旋转精灵



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

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

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)

最新更新