ios - 如何在 SpriteKit 中将 Sprite 旋转 90 度

标签 ios math sprite-kit

我正在尝试将 sprite 旋转 90 度,所以如果我在它上面点击,它会移动 90 度并面向那个方向。像蛇游戏一样思考。

在我的 touchesBegan 方法中,我可以让 Sprite 旋转,但它似乎会自行翻转,而不是实际旋转 90 度,更像是 180 度。

关于为什么以及如何让它指向正确方向的任何想法。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    let touch = touches.first as UITouch!
    let touchLocation = touch.locationInNode(self)
    sceneTouched(touchLocation)

    if (car.position.x > touchLocation.x) {
        car.zRotation = CGFloat(M_PI_2)
    } else {
        car.zRotation = CGFloat(-M_PI_2)
    }
}

最佳答案

基于您的代码对我有用的事实,我会说这可能是因为 car.zRotation 的当前值不是 0.0 而是类似于 -M_PI_2。因此,当您将其设置为 M_PI_2 时,您会旋转 180 度。在设置新值之前尝试打印 car.zRotation

关于ios - 如何在 SpriteKit 中将 Sprite 旋转 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34330065/

相关文章:

ios - 设置子 Pane 的值

ios - 对象 : ARC releasing dynamically created view controller too early

javascript - 如何在提供迭代次数的同时获取两个数字之间的值范围?

c++ - 旋转后找到三角形的点

ios - 如何在 [SKAction rotateBy :duration:] 期间获得正确的 zRotation

ios - 我想使用 swift 添加标签或文本,如下图所示

ios - 当应用程序处于后台时,如何显示自定义本地通知 View 或自定义警报 View ?

algorithm - 矩阵正定和病态的迭代线性求解器

swift - SKCameraNode.position didSet 在使用 SKAction 移动时不会被触发

ios - 为什么我的第二个场景是空的?