繁体   English   中英

如何在SpriteKit中将Sprite旋转90度

[英]How to rotate a Sprite 90 degrees in SpriteKit

我试图将精灵增加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的事实,我可以说这可能是因为car.zRotation的当前值不是0.0而是类似-M_PI_2 因此,将其设置为M_PI_2您会旋转180度。 设置新值之前,请尝试打印car.zRotation

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM