|
38 | 38 | // |
39 | 39 | // type Game struct{ scene *willow.Scene } |
40 | 40 | // |
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) } |
43 | 43 | // func (g *Game) Layout(w, h int) (int, int) { return w, h } |
44 | 44 | // |
45 | 45 | // # Scene graph |
|
51 | 51 | // [NewText], [NewParticleEmitter], [NewMesh], [NewPolygon], and others. |
52 | 52 | // |
53 | 53 | // container := willow.NewContainer("ui") |
54 | | -// scene.Root().AddChild(container) |
| 54 | +// scene.Root.AddChild(container) |
55 | 55 | // |
56 | 56 | // sprite := willow.NewSprite("hero", atlas.Region("hero_idle")) |
57 | 57 | // sprite.SetPosition(100, 50) |
|
70 | 70 | // [Node.FindDescendant] (recursive depth-first). Both support % wildcards: |
71 | 71 | // |
72 | 72 | // bar := enemy.FindChild("health_bar") |
73 | | -// boss := scene.Root().FindDescendant("boss%") // starts with "boss" |
| 73 | +// boss := scene.Root.FindDescendant("boss%") // starts with "boss" |
74 | 74 | // |
75 | 75 | // For repeated lookups or tag-based grouping, use [NodeIndex]: |
76 | 76 | // |
|
92 | 92 | // [EaseOutCubic], [EaseOutBounce], etc. for autocomplete discoverability |
93 | 93 | // without an extra import. |
94 | 94 | // |
| 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 | +// |
95 | 122 | // See the full docs for guides on each feature: |
96 | 123 | // https://www.devthicket.org/willow |
97 | 124 | // |
98 | 125 | // [Ebitengine]: https://ebitengine.org |
99 | 126 | // [Starling]: https://gamua.com/starling/ |
100 | 127 | // [PixiJS]: https://pixijs.com/ |
101 | 128 | // [gween]: https://github.com/tanema/gween |
| 129 | +// [Chipmunk]: https://github.com/jakecoffman/cp |
102 | 130 | package willow |
0 commit comments