How to Add a Camera in Defold: A Complete Guide
Defold handles cameras differently from many other game engines, and that surprises a lot of developers coming from Unity or Godot. Understanding the system properly — rather than just copying a snippet — will save you significant debugging time and give you real control over how your game world is rendered.
What a Camera Actually Does in Defold
In Defold, a camera component doesn't move the world or transform your game objects directly. Instead, it communicates with the render pipeline to define what portion of the game world gets drawn to the screen and how.
When a camera is active, it sends view and projection matrices to the render script. Those matrices tell the renderer which coordinate space to use when drawing. Without a camera sending those messages, the render script falls back to default behavior — typically a static view anchored to the world origin.
This distinction matters because adding a camera in Defold involves two separate concerns:
- Placing the camera in your game scene
- Ensuring the render script listens to the camera
Both steps are necessary. Many developers add the camera component correctly but wonder why nothing changes — it's usually because the render script isn't configured to use it.
Step 1: Add the Camera Component to a Game Object
To add a camera in Defold:
- Open or create a game object (.go file) in your project, or add the camera directly inside a collection.
- Right-click the game object in the Outline panel and select Add Component.
- Choose Camera from the component list.
- The camera component will appear with the following configurable properties:
| Property | What It Controls |
|---|---|
| Aspect Ratio | Width-to-height ratio of the rendered view |
| FOV (Field of View) | Vertical angle of the view frustum (3D games) |
| Near Z / Far Z | Depth clipping planes — what's too close or too far to render |
| Auto Aspect Ratio | Automatically match the window's current aspect ratio |
| Orthographic Projection | Enables flat 2D-style rendering with no perspective |
| Orthographic Zoom | Scales the view in orthographic mode |
For 2D games, orthographic projection is almost always the correct choice. For 3D games, perspective projection using FOV gives objects a sense of depth.
Step 2: Acquire the Camera from a Script
Simply placing a camera component isn't enough to activate it. You need to send an acquire_camera_focus message from a script attached to the same game object (or a nearby one that references it).