See a few examples of what keyframe sequence can do.
The primary use for an
SKKeyframe object is to animate properties on particles emitted by an
SKEmitter object. When a keyframe object is assigned to an appropriate property on the emitter node, particles determine their values by sampling the keyframe sequence. The sequence replaces the normal simulation performed by the emitter node. Only certain properties can be animated using a keyframe sequence. The following table lists the particle emitter properties and the corresponding class for the data that must be stored in the sequence. All value objects stored in a sequence must have the same class.
The time values stored in the sequence are specified in a normalized range of
0 is the time when the particle was created and
1 is the time when the particle dies. You can provide keyframe values for the entire lifetime of the particle or for a subset of the particle’s lifetime. If you choose to cover only a subset of the particle’s lifetime, the
repeat property determines how samples are determined for time values that lie outside the specified range.
interpolation property determines how samples between the keyframe values are calculated.
SKKeyframe isn’t limited to working only with
SKEmitter, you can use the
sample method to generate values interpolated between keyframes for other applications. The following code shows how to create a sequence containing four keyframes and how to iterate over the interpolated values:
SKInterpolation interpolation, the code above creates the following graph in a playground:
SKKeyframe can also interpolate colors. The following code shows how to initialize a sequence with four colors and sample the interpolated values:
The samples for each color generated by the code above can be used to create a gradient: