Contents

FromToByAction

An action that starts, stops, or increments by a specific value.

Declaration

struct FromToByAction<Value> where Value : AnimatableData

Overview

This action animates a bound parameters value over time. Specifying a from value represents the animated properties’ initial value at the start of the animation. Specifying a to determines the value of the property at the end of the animation. Specifying aby adds a value to the properties initial state, which calculates the value at the end of the animation.

This action exposes FromToByAction.TransformMode which is used when animating a Transform property. Use this mode to determine the reference space the property is relative to. For example, FromToByAction.TransformMode.local means the provided transforms are relative to the transform of the bound entity. The only exception is when by is specified, this is relative to the space of the starting transform.

Creating a from, to, by action to animate an entity’s opacity

The example below creates an animation which gradually animates the bound entity’s opacity property for five seconds with a linear transition. In this example, the entity starts with opacity at 1.0.

// Create an action that gradually animates a float value
// towards `0.0`, with a linear transition.
//
// This action does not have a `from` value supplied, 
// meaning this starts from the default source value.
let opacityAction = FromToByAction<Float>(to: 0.0,
                                          timing: .linear,
                                          isAdditive: false)

// A five second animation that plays an animation causing the entity to
// gradually animate the `.opacity` property towards `0.0`.
//
// This makes the entity fade-out.
let opacityAnimation = try AnimationResource
    .makeActionAnimation(for: opacityAction,
                         duration: 5.0,
                         bindTarget: .opacity)

// Play the five second animation on the entity that will fade-out.
entity.playAnimation(opacityAnimation)

Create a from, to, by action to animate an entity’s transform property

The example below creates an animation which gradually animates the bound entities transform property for five seconds with a linear transition.

// Create a transform to start animating from.
let startTransform = Transform(translation: [0.0, 2.0, 0.0])

// Create a transform to animate towards.
let endTransform = Transform(translation: [0.0, -2.0, 0.0])

// Create an action that gradually animates a transform value.
//
// This starts `from` a specified value, and animates towards
// a specified `to` value.
//
// The bound entity will move in the space relative to its parent.
let transformAction = FromToByAction<Transform>(from: startTransform,
                                                to: endTransform,
                                                mode: .parent,
                                                timing: .linear,
                                                isAdditive: false)

// A five second animation that plays an animation causing 
// the entity to gradually move from a specific start, and end transform
let transformAnimation = try AnimationResource
    .makeActionAnimation(for: transformAction,
                         duration: 5.0,
                         bindTarget: .transform)

// Play the five second animation on the entity that will cause it to move.
entity.playAnimation(transformAnimation)

Topics

Initializers

Instance Properties

Enumerations

Default Implementations

See Also

Built-in actions