我創建了一個可供玩家移動的SceneKit 3D迷宮世界。一些像跳躍這樣的動作涉及在上下移動照相機的同時在幾秒鐘的時間內改變視角。在此期間,我想忽略用戶的點擊和揮動,這通常會導致其他類型的動作,如轉動和向前移動。檢查SCNNode SCNAction是否已完成
我可以創建相匹配的跳躍時間,並設置一個布爾值,但我希望檢查攝像機的SCNNode的simplier方式的計時器。
有一個簡單的方法,如果攝像機的SCNNode不再運行SCNAction的跳轉,所以我可以在其他輕觸和滑動操作的前面加上這樣的邏輯?
或者也許有一個SCNAction可以設置布爾,我可以在我的跳轉序列的開始和結束?
這裏是我的跳碼:
let jumpUp: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), jumpHeight), duration: jumpTime)
let jumpAppex: SCNAction = SCNAction.wait(duration: jumpWaitTime)
let fallDown: SCNAction = SCNAction.move(to: SCNVector3Make(Float(Int(-yPos)), Float(Int(xPos)), cameraHeight), duration: jumpTime)
var lookDown: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(π), duration: jumpTurnTime)
let noLook: SCNAction = SCNAction.wait(duration: jumpTime*2.0)
var lookBack: SCNAction = SCNAction.rotateTo(x: 0, y: 0, z: 0, duration: jumpTurnTime)
switch playerDirection.direction
{
case .south:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(southZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(southZ), duration: jumpTurnTime)
case .north:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(northZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(northZ), duration: jumpTurnTime)
case .east:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(eastZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(eastZ), duration: jumpTurnTime)
case .west:
lookDown = SCNAction.rotateTo(x: 0, y: 0, z: CGFloat(westZ), duration: jumpTurnTime)
lookBack = SCNAction.rotateTo(x: CGFloat(π/2), y: 0, z: CGFloat(westZ), duration: jumpTurnTime)
}
let sequenceJump = SCNAction.sequence([jumpUp, jumpAppex, fallDown])
let sequenceLook = SCNAction.sequence([lookDown, noLook, lookBack])
mazeScene.mazeCamera.runAction(sequenceJump)
mazeScene.mazeCamera.runAction(sequenceLook)
感謝
格雷格
有一個''runBlock' SCNAction',你可以只添加到您的順序和定塊內的布爾。還有一個'runAction:completionHandler'方法在動作完成時運行一個塊。 –
原因蘋果無法記錄自己的最佳功能,因爲這是你即將看到的。 IMNSHO,這是最好和最強大的行動,幾乎完全沒有記錄,並且從未提升它的內容,可以並且代表着承諾和潛力:https://developer.apple.com/reference/scenekit/ scnaction/1523692-customaction – Confused