The following function accepts a single SCNNode param and it uses SCNAction to continuously repeat a rotation:
func scnActionFunc(nodeParam :inout SCNNode){
let angleAmount : CGFloat = 360 * ((.pi)/180.0)
let action = SCNAction.rotate(by: angleAmount, around: SCNVector3(x: 0, y: 1, z: 0) , duration: 32.0)
let repeatAction = SCNAction.repeatForever(action)
nodeParam.runAction(repeatAction)
}
This second function accepts a single SCNNode param and it uses SCNTransaction to perform a single partial rotation:
func scnTransactionFunc(nodeParam:inout SCNNode){
SCNTransaction.begin()
SCNTransaction.animationTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
SCNTransaction.animationDuration = 3.0
nodeParam.transform = SCNMatrix4MakeRotation( -(.pi / 2.0), 1, 0, 0)
SCNTransaction.commit()
}
My questions: 1: as far as I can see, SCNTransaction does not have its own 'repeat' function - is this the case? 2: Im sure its possible to repeat an SCNTransaction in a function using Timer() or similar class but is there A canonical method for repeating SCNTransaction code over and over? Im not trying to find out about repetition itself - there are doubtlessly numerous methods of achieving repeated actions - My reason for posing this question is because Im just trying to make sure I properly understand SCNTransaction as fully as possible. Thanks.
As far as I know, there is no built-in repeat functionality within SCNTransaction. You could use probably something like this:
// Scene Transaction with completion handler example
SCNTransaction.begin()
SCNTransaction.animationDuration = 6.0
// For completion handling - enable the completionBlock
SCNTransaction.completionBlock = {
SCNTransaction.begin()
SCNTransaction.animationDuration = 1.0
explosion.particleColor = UIColor.blue
SCNTransaction.commit()
}
cameraNode.camera?.focalLength = 50
SCNTransaction.commit()
replace the content of the completionBlock by calling the function itself again.
func scnTransactionFunc(nodeParam:inout SCNNode) {
SCNTransaction.begin()
SCNTransaction.animationTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
SCNTransaction.animationDuration = 3.0
SCNTransaction.completionBlock = {
scnTransactionFunc(nodeParam:inout SCNNode)
}
nodeParam.transform = SCNMatrix4MakeRotation( -(.pi / 2.0), 1, 0, 0)
SCNTransaction.commit()
}
Note: this function will never terminate until you exit the application.
It might be better to use the example in which you use the SCNAction. This one you can terminate at any time. Using a Scheduled Timer might work as well.
Hope I could help you in some way.