Last active
June 28, 2017 21:40
-
-
Save TheNorthEestern/8fdfe1ec4b27ebe9feb9f07ed2214767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SCNAction { | |
static func oscillation(amplitude a: CGFloat, timePeriod t: Double) -> SCNAction { | |
let action = SCNAction.customAction(duration: t) { node, currentTime in | |
let displacement = a * sin(2 * .pi * currentTime / CGFloat(t)) | |
node.position.x = Float(displacement) | |
} | |
return action | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code gets excuted inside of a loop on viewDidLoad() | |
let osc = SCNAction.oscillation(amplitude: (outerLoopVal % 2 == 0 ? 10 : -10), timePeriod: 240) | |
nodeRow.runAction(SCNAction.repeatForever(osc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment