Skip to main content

Actions are Scheduled

Think of Actions as behaviors that are scheduled to happen: they may happen immediately, or they may happen later.

To run an action, call the node's run() method, and provide the Action to run as the first argument.

tip

By default, a node's Actions run only when the scene that contains the node has fully appeared on the screen. This is important to understand, because it means that you can schedule an action to happen before the scene appears.

Below, we run a Move action on the second scene's label to animate the label position on the screen.

movingLabel.run(Action.move({
point: { x: 100, y: 25 },
duration: 500,
}));

Two points:

  1. The label's Move action will run only once the second scene has fully appeared on the screen (this coincides with the second scene's OnAppear event).
  2. If you go "Back" and "Next" again, the label is already at the top. This is because we ran the action only once, and the action is now complete.
Loading...
Explore:
  • If you want the Action to run during the transition, set the option runDuringTransition to true:

    movingLabel.run(Action.move({
        point: { x: 100, y: 25 },
        duration: 500,
        runDuringTransition: true
    }));
    Now, when the second scene slides in, the label has already started its action.
  • If you want the label to reset itself and rise every time you come to the second screen:
    • Move the label's run action within the sceneTwo.onAppear() event handler so it runs every time the second scene appears and
    • Reset the label's position in the backButton.onTapDown() event handler