私は時計のようなものを手で掃除しようとしています。SKAction期間内に映画が完成しませんか?
私はNSDate
から分を引きます。
その後やや私は私のスプライトが中に移動しなければならない次のXY位置を計算し、次の分の始めに続いてラジアン値を計算し、私のスプライトが1分にまで移動しなければならないXY位置を見つけ、
その分。
私はすべてを正しく理解していますと仮定すると、更新機能
//Get Current Minute
var currentTime = NSDate();
var nowCal = NSCalendar(calendarIdentifier: NSCalendar.Identifier.ISO8601)
var currMin = nowCal?.component(.minute, from: currentTime as Date)
//Print current minute
print(currMin)
// slicing the circle into 60 segments and getting which angle in radians the sprite should move to in the next min
var minAng = (2*CGFloat.pi)/60 * CGFloat(currMin!)
//calculating point on the circle where the sprite should move to in the next min
var newPt = CGPoint(x: (300 * cos(minAng)), y: -(300 * sin(minAng)))
//print out where the sprite currently is and where it should move to
print(hand.position)
print(newPt)
//move the sprite to the new location over 60 seconds, making sure the movement is linear
let moveHand = SKAction.move(to: newPt, duration: 60)
moveHand.timingMode = SKActionTimingMode.linear
hand.run(moveHand)
//move another placeholder sprite to the final destination instantly to visualise movment by waiting for the moving sprite.
handToBe.run(SKAction.move(to: newPt, duration: 0))
内のこれらのコードを持っているので、それが次に移動する必要が前のセグメントの終わりに到達し、1分でセグメントを移動する必要がありますセグメント。
ただし、私のスプライトは次のセグメントに移動する前にセグメントの最後に到達することはありません。プリントアウトは常に遅すぎることを示しています。
何か私はSKAction.move(to:)
について理解していないか、このインスタンスに欠陥がありますか?
rotateToアクションを使用するのはなぜですか? – Knight0fDragon
私は回転していません。円軌道上を移動しなければならないスプライトです。 私はそれを1つの端に点を持つ本当に大きな透明なスプライトにすることができますが、2つの問題が存在すると思います。 スプライトを回転させて円で移動することはできません。スケールすることは難しいでしょう。 また、私はMovetoの長時間の問題を学習実験として理解しようとしており、代替方法を見つけようとはしていません。 しかし、私は、durationによって回転すると思われますが、同様に動作します。 – Eivie
はいそれは同じ振る舞いになります – Knight0fDragon