Skip to content

Commit 643e164

Browse files
committed
docs: add physics section to package doc and fix scene.Root references
- New # Physics section in doc.go covering the willow.Physics* surface, the per-frame tick + write-back, and the nophysics build tag. - Correct scene.Root() to the field scene.Root in the existing examples. - Fix the ebiten.Game stub to use the lowercase scene field. - Add Chipmunk reference link.
1 parent 70add7f commit 643e164

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

doc.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
//
3939
// type Game struct{ scene *willow.Scene }
4040
//
41-
// func (g *Game) Update() error { g.Scene_.Update(); return nil }
42-
// func (g *Game) Draw(s *ebiten.Image) { g.Scene_.Draw(s) }
41+
// func (g *Game) Update() error { g.scene.Update(); return nil }
42+
// func (g *Game) Draw(s *ebiten.Image) { g.scene.Draw(s) }
4343
// func (g *Game) Layout(w, h int) (int, int) { return w, h }
4444
//
4545
// # Scene graph
@@ -51,7 +51,7 @@
5151
// [NewText], [NewParticleEmitter], [NewMesh], [NewPolygon], and others.
5252
//
5353
// container := willow.NewContainer("ui")
54-
// scene.Root().AddChild(container)
54+
// scene.Root.AddChild(container)
5555
//
5656
// sprite := willow.NewSprite("hero", atlas.Region("hero_idle"))
5757
// sprite.SetPosition(100, 50)
@@ -70,7 +70,7 @@
7070
// [Node.FindDescendant] (recursive depth-first). Both support % wildcards:
7171
//
7272
// bar := enemy.FindChild("health_bar")
73-
// boss := scene.Root().FindDescendant("boss%") // starts with "boss"
73+
// boss := scene.Root.FindDescendant("boss%") // starts with "boss"
7474
//
7575
// For repeated lookups or tag-based grouping, use [NodeIndex]:
7676
//
@@ -92,11 +92,39 @@
9292
// [EaseOutCubic], [EaseOutBounce], etc. for autocomplete discoverability
9393
// without an extra import.
9494
//
95+
// # Physics
96+
//
97+
// Optional 2D rigid-body physics is integrated via [Chipmunk]. Enable
98+
// physics on a subtree with [Node.EnablePhysics], then attach bodies to
99+
// descendants with [Node.SetBody]. Per-frame world transforms write back
100+
// to nodes automatically after [Scene.Update]. The public surface is
101+
// re-exported under the Physics* prefix: [PhysicsConfig], [PhysicsBodyDef],
102+
// [PhysicsCircle], [PhysicsBox], [PhysicsSegment], [PhysicsPolygon], with
103+
// body kinds [PhysicsDynamic], [PhysicsStatic], and [PhysicsKinematic].
104+
//
105+
// import "github.com/jakecoffman/cp/v2"
106+
//
107+
// root := willow.NewContainer("world")
108+
// root.EnablePhysics(willow.PhysicsConfig{Gravity: cp.Vector{X: 0, Y: 900}})
109+
// scene.Root.AddChild(root)
110+
//
111+
// ball := willow.NewSprite("ball", willow.TextureRegion{})
112+
// ball.SetSize(20, 20)
113+
// root.AddChild(ball)
114+
// ball.SetBody(willow.PhysicsDynamic{
115+
// Shape: willow.PhysicsCircle{Radius: 10},
116+
// Mass: 1,
117+
// })
118+
//
119+
// Build with -tags nophysics to strip the cp dependency from the binary
120+
// for projects that do not use physics.
121+
//
95122
// See the full docs for guides on each feature:
96123
// https://www.devthicket.org/willow
97124
//
98125
// [Ebitengine]: https://ebitengine.org
99126
// [Starling]: https://gamua.com/starling/
100127
// [PixiJS]: https://pixijs.com/
101128
// [gween]: https://github.com/tanema/gween
129+
// [Chipmunk]: https://github.com/jakecoffman/cp
102130
package willow

0 commit comments

Comments
 (0)