# Camera 2D

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

```
component engine.Camera2D
```

Renders an orthographic view from the node transform.

## From a script

Zoom the camera in smoothly while a key is held, and back out when it is released.

```aes check
package game

import (
    "aego/input"
    "aego/math"
)

script ZoomCamera {
    var Normal float = 40
    var Close float = 80

    func Update(dt float) {
        cam := node.Get<Camera2D>()
        target := Normal
        if input.Down(input.KeyZ) {
            target = Close
        }
        cam.Zoom = math.Lerp(cam.Zoom, target, math.Clamp(dt*6, 0, 1))
    }
}
```

## Fields

| Name | Script name | Type | Default | Description |
|---|---|---|---|---|
| Zoom | `Zoom` | `float` | `64` | Pixels per world unit. Larger values show a smaller part of the world. |
| Viewport | `Viewport` | `Rect` | `(0, 0, 1, 1)` | Part of the screen the camera draws into, in normalized coordinates. |
| Mask | `Mask` | `int` | `-1` | Visibility layers this camera renders. -1 renders every layer. |
| Order | `Order` | `int` | `0` | Cameras with a lower order render first. |
| Clear | `Clear` | `bool` | `true` | Clears the viewport before drawing. |
| Clear Color | `ClearColor` | `Color` | `rgba(0.04, 0.05, 0.07, 1)` | Background color used when clear is on. |
| Scale | `Scale` | `enum` | `free` | How the view adapts to the window: free, pixelPerfect or fitVirtual. |
| Virtual | `Virtual` | `Vec2` | `(0, 0)` | Virtual resolution used by fitVirtual and pixelPerfect. |
| Active | `Active` | `bool` | `true` | Only active cameras render. |
