Transitions
Note: These docs were adopted from the original Motion Canvas docs
Transitions allow you to customize the way scenes transition from one into another. A transition is an animation performed at the beginning of the scene. It can modify the context of both the current and the previous scene.
Before we startβ
Make sure your project contains at least two scenes. In this example, we've prepared firstScene.tsx and secondScene.tsx, and configured our project to display one after the other. We'll be setting up our transitions in the second scene.
Make sure to put something different in both scenes to easier see the transitions.
my-animation/
ββ src/
ββ scenes/
β ββ firstScene.tsx
β ββ secondScene.tsx
ββ project.tsPre-made transitionsβ
Motion Canvas comes with a set of common transitions in a form of easy-to-use generators. To use them, yield* the transition generator at the beginning of the new scene:
src/scenes/secondScene.tsx
export default makeScene2D(function* (view) {
// set up the scene:
view.add(/* your nodes here */);
// perform a slide transition to the left:
yield* slideTransition(Direction.Left);
// proceed with the animation
yield* waitFor(3);
});All available transitions are listed below:
slideTransitionβ
slideTransitionβPerform a transition that slides the scene in the given direction.
Parameters
direction: DirectionThe direction in which to slide.
duration?: numberThe duration of the transition.
zoomInTransitionβ
zoomInTransitionβPerform a transition that zooms in on a given area of the scene.
Parameters
area: BBoxThe area on which to zoom in.
duration: number = 0.6The duration of the transition.
zoomOutTransitionβ
zoomOutTransitionβPerform a transition that zooms out from a given area of the scene.
Parameters
area: BBoxThe area from which to zoom out.
duration: number = 0.6The duration of the transition.
fadeTransitionβ
fadeTransitionβPerform a transition that fades between the scenes.
Parameters
duration: number = 0.6The duration of the transition.
Custom transitionsβ
You can use the useTransition function to implement custom transitions. It allows you to specify two callbacks that will modify the contexts of the current and previous scene respectively. The value it returns is a callback that you need to call once you finish the transition.
The transition template looks as follows:
Here's how you could implement a simple slide transition:
Animate when transitioningβ
By default, Motion Canvas will transition to the next scene once the generator of the current scene has reached the end. In this case, the scene will freeze for the duration of the transition. You can use the finishScene function to trigger the transition early, allowing the animation to continue while transitioning:
Last updated