Contents

timingFunction

A block used to customize the timing function.

Declaration

var timingFunction: SKActionTimingFunction { get set }

Mentioned in

Discussion

If a timing function is provided, after the normal timing mode is applied, the result is sent to the timing function. The return SKActionTimingFunction value of the timing function determines the actual time used to perform the animation.

The following code shows how you can create a custom timing function using simd_smoothstep(_:_:_:) interpolation:

import simd
let horizontalAction = SKAction.moveTo(x: end.x, duration: 2.0)
horizontalAction.timingFunction = {
    time in
    return simd_smoothstep(0, 1, time)
}

If the above code is combined with a vertical linear move action, the path taken by a node running this action describes the curve illustrated below:

[Image]

See Also

Controlling Action Timing