[英]Rotation of Sprite in touch event
如何在触摸事件中旋转SpriteNode?
这里是到目前为止的代码:
// Detect what side of the screen the user has touched.
if(touchLocation.x < 160) {
// They've touched the left side (the car turns left)
[car runAction:[SKAction rotateByAngle:-50 duration:0]];
[car.physicsBody applyImpulse:CGVectorMake(-20,0)];
car.physicsBody.velocity = CGVectorMake(-20, 0);
}else{
// They've touched the right side (the car turns right)
[car runAction:[SKAction rotateByAngle:50 duration:0]];
[car.physicsBody applyImpulse:CGVectorMake(20,0)];
_bird.physicsBody.velocity = CGVectorMake(20, 0);
}
即使其他Stackoverflow问题已将其作为可接受的答案,-50的旋转也不起作用。 正常的50度转弯似乎也可以工作一秒钟,然后恢复到原始位置。
我如何使旋转保持平稳并旋转?
当您使用rotateByAngle
它以弧度为单位。 一圈约有6个弧度。 因此,您需要多次旋转此精灵。 这并不是您所期望的50度转弯。 您需要使用CGFloat(M_PI)
变体。 如果要在度和弧度之间转换,则转换为
let radians = CGFloat(M_PI) * degrees / 180.0
从那里开始,然后查看精灵是否以更可预测的方式运行
由于动画的持续时间为0,因此实际上没有理由在其中使用动作。
car.zRotation = radians
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.