Skip to content

Scenes & Entities

Scenes are the foundation of labelle games. They define what entities exist and how they’re configured.

Scenes are defined in .zon files in the scenes/ directory:

scenes/level1.zon
.{
.name = "level1",
.scripts = .{"gravity", "collision"},
.camera = .{ .x = 0, .y = 0, .zoom = 1.0 },
.entities = .{
.{
.id = "player",
.prefab = "player",
.components = .{ .Position = .{ .x = 100, .y = 100 } },
},
.{
.prefab = "enemy",
.components = .{ .Position = .{ .x = 500, .y = 100 } },
},
},
}

Reference a prefab template with optional component overrides:

.{ .prefab = "player", .components = .{ .Position = .{ .x = 100, .y = 100 } } }

Define an entity directly without a prefab:

.{
.components = .{
.Position = .{ .x = 200, .y = 200 },
.Shape = .{ .type = .circle, .radius = 50 },
},
}

Named entities can be looked up at runtime:

if (scene.getEntityByName("player")) |player| {
// Do something with player
}

Change scenes using the Game API:

game.queueSceneChange("level2");

Set camera position and zoom:

.camera = .{ .x = 0, .y = 0, .zoom = 2.0 }

Or use named cameras for split-screen:

.cameras = .{
.main = .{ .x = 0, .y = 0 },
.player2 = .{ .x = 100, .y = 0 },
}