How to Add a FadeOut Duration to a SCNAction

旧巷老猫 提交于 2019-12-06 14:46:36

问题


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).

  1. Linear (the default, what you're seeing)
  2. Ease In (Slow start, Fast finish)
  3. Ease Out (Fast start, Slow finish)
  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!