Skip to content

<Camera> ​

One view over the tracks written inside it: they move, zoom and turn together, by a constant or by keys on the video's clock. Tracks outside it stay fixed to the screen. A composition has one, or none.

tsx
import { Camera, Clip, Composition, Shape, Title, Track } from "@uberscene/kit";

export default function Video() {
  return (
    <Composition fps={30} width={960} height={540} background={{ type: "color", color: "#3447ff" }}>
      {/* Everything on the camera's tracks moves together: here it pans to make room, then pulls back. */}
      <Camera
        id="cam"
        x={[
          { at: 1, value: 0, easing: "snappy" },
          { at: 1.3, value: -70 },
        ]}
        zoom={[
          { at: 2.2, value: 1, easing: "snappy" },
          { at: 2.5, value: 0.88 },
        ]}
      >
        <Track id="subject" layout="free">
          <Clip
            id="pour"
            src="asset:espresso"
            start={0}
            in={6}
            duration={4}
            volume={0}
            fit="cover"
            box={{ x: 480, y: 280, width: 400, height: 225, origin: "center" }}
            transform={{ borderRadius: 16 }}
          />
        </Track>
        <Track id="cards" layout="free">
          <Shape
            id="card"
            type="rectangle"
            start={1}
            duration={3}
            width={150}
            height={190}
            cornerRadius={12}
            fill="#ffffff"
            box={{ x: 130, y: 280, origin: "center" }}
            enter={{ type: "pop", duration: 0.3 }}
          />
          <Shape
            id="card-2"
            type="rectangle"
            start={2.2}
            duration={1.8}
            width={150}
            height={190}
            cornerRadius={12}
            fill="#ffffff"
            box={{ x: 870, y: 280, origin: "center" }}
            enter={{ type: "pop", duration: 0.3 }}
          />
        </Track>
      </Camera>
      {/* A track outside the camera stays fixed to the screen. */}
      <Track id="brand" layout="free">
        <Title id="mark" start={0} duration={4} box={{ x: 480, y: 48, origin: "center" }} style={{ size: 20 }}>
          fixed to the screen
        </Title>
      </Track>
    </Composition>
  );
}

The coffee footage is Pixabay videos 209419, 209424, 46989 and 251, under the Pixabay Content License. The maker of the machine in the red cup shot has nothing to do with this project.

Props ​

proptypedefaultrequireddescription
idstringyesThe camera's name in the file; actions refer to it by this.
xnumber | { at, value, easing }[] | { type, base, amount, frequency, seed } | { type, base, speed } | { type, keys, direction, iterationCount } |How far the view has moved right, in pixels: at 180 everything under the camera sits 180 px to the left.
ynumber | { at, value, easing }[] | { type, base, amount, frequency, seed } | { type, base, speed } | { type, keys, direction, iterationCount } |How far the view has moved down, in pixels: at 100 everything under the camera sits 100 px higher.
zoomnumber (0.01..100) | { at, value, easing }[] | { type, base, amount, frequency, seed } | { type, base, speed } | { type, keys, direction, iterationCount } |How close the view is, about the frame's centre: 1 is as written, 2 shows everything twice the size.
rotationnumber | { at, value, easing }[] | { type, base, amount, frequency, seed } | { type, base, speed } | { type, keys, direction, iterationCount } |How far the view is turned clockwise, in degrees, about the frame's centre: what it shows turns the other way.
pushLets the camera make room: as each element in on starts, the view moves as little as it can so that element is in view with everything else on the camera's tracks that is on screen then. It pans the shortest way, and pulls back only when all of it cannot fit. With push, x, y and zoom are where the view starts, as numbers; camera/bakePush turns the moves into keys to change by hand.

Children: track. All elements

MIT licensed.