我有一個行爲,我不明白使用SceneKit動畫時的情況。 以下所有代碼均在渲染器的上下文中執行:updateAtTime:delegate調用。SceneKit在動畫開始時閃爍
我建我的動畫是這樣的:
SCNVector4 startRotation = node.rotation ;
SCNVector4 targetRotation = pose.rotation ;
CABasicAnimation *rotAnimation = [CABasicAnimation animationWithKeyPath:@"rotation"] ;
rotAnimation.fromValue = [NSValue valueWithSCNVector4:startRotation] ;
rotAnimation.toValue = [NSValue valueWithSCNVector4:targetRotation] ;
rotAnimation.duration = duration ;
現在,如果我以後這樣做的權利:
// First change the final rotation state, and then start the animation
node.rotation = targetRotation ;
[node addAnimation:rotAnimation forKey:animationName] ;
我的性格在最後位置的快速閃過,然後動畫從startRotation運行到targetRotation並永遠保持在targetRotation位置 - 這是我想要的,除了閃光燈。
如果我這樣做,而不是(只是交換最後兩行排列):
// First start the animation and then set the final position
[node addAnimation:rotAnimation forKey:animationName] ;
node.rotation = targetRotation ;
我沒有閃光燈,但是當動畫結束,字符回到初始位置,這是不是我想要的。
我讀了關於fillMode和removedOnCompletion,但將removedOnCompletion設置爲NO並不是正確的做法,因爲它會讓動畫永遠「運行」。
如何避免初始閃光?
我認爲你應該在'renderer:updateAtTime:'之外做你的動畫,因爲文檔說任何場景變化都會立即應用。 (所以我猜節點在添加動畫之前已經更新了。) –
好吧,差不多......我認爲當你說「在渲染器之外做你的動畫:updateAtTime:」時你是對的。但是,並不是因爲立即應用更改。我經歷了漫長的調查,我想我現在明白髮生了什麼。爲了簡短起見,如果在渲染器內執行,我的代碼完美工作(不閃光):didRenderScene:atTime :.爲了記錄和幫助他人,我會寫詳細的解釋並回答我自己的問題。 –