我有以下自定义SKAction工作,但作为EaseIn而不是EaseOut。我想要它EaseOut!我使用在网络上找到的各种缓动方程式来纠正它是惨不忍睹的。
let duration = 2.0
let initialX = cameraNode.position.x
let customEaseOut = SKAction.customActionWithDuration(duration, actionBlock: {node, elapsedTime in
let t = Double(elapsedTime)/duration
let b = Double(initialX)
let c = Double(targetPoint.x)
let p = t*t*t*t*t
let l = b*(1-p) + c*p
node.position.x = CGFloat(l)
})
cameraNode.runAction(customEaseOut)
任何帮助都会非常感激。
由于
答案 0 :(得分:11)
您无需计算它。
SKAction
只有一个名为timingMode
的属性:
// fall is an SKAction
fall.timingMode = .easeInEaseOut
您可以选择:
如果您需要更改Apple预设,可以使用:timingFunction
fall.timingFunction = { time -> Float in
return time
}
根据来源构建自定义函数:
/**
A custom timing function for SKActions. Input time will be linear 0.0-1.0
over the duration of the action. Return values must be 0.0-1.0 and increasing
and the function must return 1.0 when the input time reaches 1.0.
*/
public typealias SKActionTimingFunction = (Float) -> Float
因此,您可以写下这些信息:
func CubicEaseOut(_ t:Float)->Float
{
let f:Float = (t - 1);
return f * f * f + 1;
}
fall.timingFunction = CubicEaseOut
答案 1 :(得分:2)