我正試圖用掃手的方式製作一些東西。SKAction Moveto沒有在持續時間內完成?
我從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
我不旋轉。它是一個必須在圓形路徑上行進的精靈。 我想我可以使它成爲一個非常大的透明精靈,在一端有一個點,但隨後會出現2個問題。 我無法旋轉精靈並將它移動到一個圓圈內,這將很難縮放。 另外,重點是我想了解Moveto中的持續時間問題作爲一個學習實驗,而不是試圖找到一種替代方法。 但是,我懷疑旋轉時間可能表現相似。 – Eivie
是的,它會是相同的行爲 – Knight0fDragon