Quickstart
Quickstart
This page shows how to install Ark, and gives a minimal usage example.
Finally, it points into possible directions to continue.
Installation
To use Ark in a Go project, run:
1go get github.com/mlange-42/ark
Usage example
Here is the classical Position/Velocity example that every ECS shows in the docs.
1package main
2
3import (
4 "math/rand/v2"
5
6 "github.com/mlange-42/ark/ecs"
7)
8
9// Position component
10type Position struct {
11 X float64
12 Y float64
13}
14
15// Velocity component
16type Velocity struct {
17 X float64
18 Y float64
19}
20
21func main() {
22 // Create a new World.
23 world := ecs.NewWorld()
24
25 // Create a component mapper.
26 mapper := ecs.NewMap2[Position, Velocity](&world)
27
28 // Create entities.
29 for range 1000 {
30 // Create a new Entity with components.
31 _ = mapper.NewEntity(
32 &Position{X: rand.Float64() * 100, Y: rand.Float64() * 100},
33 &Velocity{X: rand.NormFloat64(), Y: rand.NormFloat64()},
34 )
35 }
36
37 // Create a filter.
38 filter := ecs.NewFilter2[Position, Velocity](&world)
39
40 // Time loop.
41 for range 5000 {
42 // Get a fresh query.
43 query := filter.Query()
44 // Iterate it
45 for query.Next() {
46 // Component access through the Query.
47 pos, vel := query.Get()
48 // Update component fields.
49 pos.X += vel.X
50 pos.Y += vel.Y
51 }
52 }
53}
What’s next?
If you ask “What is ECS?”, take a look at the great ECS FAQ by Sander Mertens, the author of the Flecs ECS.
To learn how to use Ark, read the following chapters, browse the API documentation, or take a look at the examples in the GitHub repository.