问题
Hey im trying to figure out how to end scnActions moveto action with a fade out duration. Basically i have a car the car moves to the spot but then suddenly stops Once the action is complete. I was hoping to try and get the car to stop more smoothly. but really i need to figure out how to get a fade out duration on an scnAction anyway. Also I checked on Apple's Developer page but that didn't help. And If the solution is there. I don't know how to put it into usable swift code.
Failed Code With Errors
let moveAction = SCNAction.moveTo(location, duration: 1.5)
moveAction.fadeInWithDuration = 1
moveAction.fadeIn(withDuration: 1)
moveAction = SCNAction.fadeIn(withDuration: 1)
moveAction.fadeOut(1.0)
moveAction.fadeOutWithDuration = 1
回答1:
You'll need to adjust the Timing Mode of your actions to get smooth, slowing movement/changes over time. There are four different modes in Scene Kit (and Sprite Kit).
- Linear (the default, what you're seeing)
- Ease In (Slow start, Fast finish)
- Ease Out (Fast start, Slow finish)
- Ease In and Out (Slow finish, fast middle, Slow finish)
This is set via an enum: SCNActionTimingMode that has each of these as a case.
Thanks to the brevity of Swift 3.0, it now looks like this:
let moveAction = SCNAction.move(to: location, duration: 1.5)
moveAction.timingMode = .easeInEaseOut
There's a much more diverse array of timing action offerings here:
https://github.com/craiggrummitt/SpriteKitEasingSwift
来源:https://stackoverflow.com/questions/39690459/how-to-add-a-fadeout-duration-to-a-scnaction