簡體   English   中英

觸摸事件中精靈的旋轉

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM