77 game-dev skills for AI coding agents — Godot, Unity, Unreal, Phaser, PixiJS, three.js, Bevy, pygame, LÖVE, Roblox. Portable SKILL.md Agent Skills (the format Anthropic launched as Claude Skills), with a router that loads the right skill for your engine and task. Runs in Claude Code, Cursor, Kiro, Codex, Copilot, Gemini CLI and more.
Python agent-skillsai-agentsantigravityawesome-listclaude-codeclinecodexcursorgame-devgame-developmentgamedevgemini-cligithub-copilotgodotkirooh-my-piskillsunityunrealwindsurf
feat(godot): add godot-ui-control, godot-animation, godot-shaders skills
AbhishekBarali1a0136c43118c
diff --git a/skills/godot/godot-animation/SKILL.md b/skills/godot/godot-animation/SKILL.mdnew file mode 100644index 0000000..bb4e728--- /dev/null+++ b/skills/godot/godot-animation/SKILL.md@@ -0,0 +1,129 @@+---+name: godot-animation+description: >+ Animate in Godot 4.x three ways: AnimationPlayer for keyframed clips (incl. call+ and signal tracks), AnimationTree with state machines and blend spaces for+ character animation, and Tween for short procedural/UI tweens via create_tween().+ Use when working with AnimationPlayer/AnimationTree nodes in a .tscn, blending+ character states, sprite-sheet animation, or code-driven Tweens.+license: Apache-2.0+compatibility: Godot 4.3++metadata:+ engine: godot+ category: godot+ difficulty: intermediate+---++# Godot Animation (4.x)++Choose and drive the right animation tool: `AnimationPlayer` (clips), `AnimationTree`+(blending/state machines), or `Tween` (short procedural moves). Targets **Godot 4.3+**.++## When to use++- Use when playing keyframed animations, blending walk/run/idle states, animating a+ sprite sheet, or tweening UI/objects in code.++**When *not* to use:** the movement *logic* that decides which state to play →+`godot-2d-movement`; UI layout (vs. UI tweening) → `godot-ui-control`; shader-driven+effects → `godot-shaders`.++## Core workflow++1. **Pick the tool:**+ - `AnimationPlayer` — author keyframed clips (transforms, properties, method calls,+ audio, even other animations). The source of truth for clip data.+ - `AnimationTree` — blend and transition between those clips at runtime with a state+ machine and/or blend spaces. Needs an `AnimationPlayer` to pull clips from.+ - `Tween` — fire-and-forget procedural interpolation in code (`create_tween()`); ideal+ for UI pops, fades, and one-off moves.+2. **For 2D sprite sheets:** use `AnimatedSprite2D` + `SpriteFrames`, or keyframe the+ `frame` property in an `AnimationPlayer`.+3. **For characters:** build clips in `AnimationPlayer`, then add an `AnimationTree`+ (`active = true`), set its `anim_player`, and design an `AnimationNodeStateMachine` or+ `AnimationNodeBlendSpace2D` as the tree root.+4. **Drive transitions from code** via the playback object (`travel`) or by setting blend+ parameters.+5. **React to clip events** with the `animation_finished` signal and call/method tracks.++## Patterns++### 1. AnimationPlayer: play a clip and await it++```gdscript+@onready var anim: AnimationPlayer = $AnimationPlayer++func attack() -> void:+ anim.play("attack")+ await anim.animation_finished # resume after the clip ends+ anim.play("idle")+```++### 2. AnimationTree state machine: travel between states++```gdscript+@onready var tree: AnimationTree = $AnimationTree++func _ready() -> void:+ tree.active = true # the tree drives animation; AnimationPlayer is the source++func set_state(state: StringName) -> void:+ # The playback object controls an AnimationNodeStateMachine root.+ var sm: AnimationNodeStateMachinePlayback = tree.get("parameters/playback")+ sm.travel(state) # transitions using the graph's connections++func _physics_process(_d: float) -> void:+ set_state(&"run" if velocity.length() > 5.0 else &"idle")+```++### 3. Blend space: blend run direction by a 2D parameter++```gdscript+# Root is an AnimationNodeBlendSpace2D named "Move" with idle/run points placed in it.+func update_locomotion(input_dir: Vector2) -> void:+ # Parameter path = "parameters/<node name>/blend_position".+ tree.set("parameters/Move/blend_position", input_dir)+```++### 4. Tween: fade and scale a UI element (code-driven)++```gdscript+func pop_in(node: Control) -> void:+ node.scale = Vector2.ZERO+ node.modulate.a = 0.0+ var tw := create_tween() # bound to this node's tree+ tw.set_parallel(true) # run the two tweens together+ tw.tween_property(node, "scale", Vector2.ONE, 0.2) \+ .set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)+ tw.tween_property(node, "modulate:a", 1.0, 0.2) # sub-property via ":"+```++## Pitfalls++- **`AnimationTree.active` left false** → nothing animates and `travel()` appears to do+ nothing. Set `active = true` and assign the `anim_player` path.+- **Wrong parameter path.** Blend/condition paths are `"parameters/<NodeName>/..."` and+ must match the node names in the tree exactly (e.g. `"parameters/playback"`,+ `"parameters/Move/blend_position"`). A typo silently no-ops.+- **AnimationPlayer and AnimationTree fighting.** When an `AnimationTree` is active, don't+ also call `AnimationPlayer.play()` for the same tracks — let the tree own playback.+- **3.x Tween node is gone.** There is no `Tween` node to add in 4.x; create tweens in+ code with `create_tween()` (a `SceneTreeTween`). They auto-start and free themselves.+- **Reusing a finished tween.** A tween is one-shot; call `create_tween()` again for a new+ animation. Use `set_loops()` for repetition.+- **`yield`/`yield(anim, "...")` is gone.** Use `await anim.animation_finished`.+- **Sub-property tweens** use a colon: `"modulate:a"`, `"position:x"`. Tweening the whole+ property instead overwrites siblings.++## References++- For state machine transitions/conditions, root motion, one-shot/blend nodes, method &+ call tracks, `SpriteFrames`/`AnimatedSprite2D`, and Tween easing/chaining/callbacks,+ read `references/animation-tree-and-tween.md`.++## Related skills++- `godot-2d-movement` — supplies the velocity/state that selects animations.+- `godot-ui-control` — UI that Tweens animate.+- `godot-3d-essentials` — 3D character scenes driven by AnimationTree.+- `game-ai` — state machines that mirror animation states.diff --git a/skills/godot/godot-animation/references/animation-tree-and-tween.md b/skills/godot/godot-animation/references/animation-tree-and-tween.mdnew file mode 100644index 0000000..5f85e58--- /dev/null+++ b/skills/godot/godot-animation/references/animation-tree-and-tween.md@@ -0,0 +1,90 @@+# AnimationTree & Tween reference (Godot 4.3+)++Depth companion to `godot-animation`.++## AnimationPlayer essentials++- Author clips in the editor's Animation panel; each clip keys node properties over time.+- Track types: **Property** (most common), **3D Position/Rotation/Scale**, **Method**+ (call a function at a keyframe), **Call** track, **Bezier** (curved value), **Audio**,+ **Animation** (play another AnimationPlayer's clip).+- Playback: `play("name")`, `play_backwards("name")`, `stop()`, `pause()`,+ `seek(time, true)`, `speed_scale`, `queue("next")`.+- Signals: `animation_finished(name)`, `animation_started(name)`,+ `current_animation_changed(name)`.+- Set a clip's loop mode in the panel (None / Linear / Ping-Pong).++A **method track** calls a function on the keyed node — great for spawning a hitbox at the+exact attack frame. A **call track** is similar via the editor's "Functions" track.++## AnimationTree nodes++Set `AnimationTree.tree_root` to one of:++- `AnimationNodeStateMachine` — named states with transitions. Drive via the playback+ object:+ ```gdscript+ var sm: AnimationNodeStateMachinePlayback = tree.get("parameters/playback")+ sm.travel("attack") # finds a path through transitions to "attack"+ sm.start("idle") # jump immediately, ignoring transitions+ sm.get_current_node() # current state name+ ```+ Transitions can be set to **Immediate**, **Sync**, or **At End**, and gated by+ **advance conditions** (booleans you set: `tree.set("parameters/conditions/is_dead", true)`)+ or an advance expression.+- `AnimationNodeBlendSpace1D` / `BlendSpace2D` — place clips at points; set+ `"parameters/<name>/blend_position"` to blend between them (e.g. directional locomotion).+- `AnimationNodeBlendTree` — a graph of blend/add/one-shot nodes with named outputs.+- `AnimationNodeOneShot` — fire a one-off (e.g. a hit reaction) over a base animation:+ ```gdscript+ tree.set("parameters/Shot/request", AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE)+ ```++Parameter path rule: `"parameters/" + node_name + "/" + property`. The playback for the+root state machine is always `"parameters/playback"`.++## Root motion++For animations that move the character via the skeleton: set+`AnimationTree.root_motion_track` to the motion track, then each physics frame apply+`tree.get_root_motion_position()` (and rotation) to the body. Useful for cinematic,+animation-driven locomotion.++## AnimatedSprite2D (sprite sheets)++```gdscript+@onready var spr: AnimatedSprite2D = $AnimatedSprite2D # uses a SpriteFrames resource++func face(dir: float) -> void:+ spr.flip_h = dir < 0.0+ spr.play("walk") # animation names defined in the SpriteFrames editor+ # spr.frame, spr.speed_scale, signal animation_finished, frame_changed+```++`SpriteFrames` holds named animations, each a list of texture frames with an FPS and loop+flag. Alternatively, keyframe `frame` / `region_rect` in an `AnimationPlayer`.++## Tween (create_tween) details++```gdscript+var tw := create_tween()+tw.tween_property(obj, "position", target, 0.5) # interpolate a property+tw.tween_property(obj, "modulate:a", 0.0, 0.3) # sub-property+tw.tween_interval(0.2) # wait+tw.tween_callback(func(): print("done")) # call a function+tw.tween_method(_set_progress, 0.0, 1.0, 1.0) # call setter over time++tw.set_parallel(true) # subsequent tweens run together (default is sequential)+tw.set_loops(3) # repeat (0 = infinite)+tw.set_trans(Tween.TRANS_SINE)+tw.set_ease(Tween.EASE_IN_OUT)+await tw.finished # signal when complete+tw.kill() # cancel early+```++Transitions: `TRANS_LINEAR/SINE/QUINT/QUART/QUAD/EXPO/ELASTIC/CUBIC/CIRC/BOUNCE/BACK/SPRING`.+Eases: `EASE_IN/OUT/IN_OUT/OUT_IN`. Chain methods on the returned `PropertyTweener`:+`.set_delay(0.1)`, `.from(start)`, `.from_current()`, `.as_relative()`.++A tween created with `create_tween()` is bound to the node's tree and is killed if the+node leaves the tree. Use `get_tree().create_tween()` to outlive a specific node.diff --git a/skills/godot/godot-shaders/SKILL.md b/skills/godot/godot-shaders/SKILL.mdnew file mode 100644index 0000000..90c66ec--- /dev/null+++ b/skills/godot/godot-shaders/SKILL.md@@ -0,0 +1,151 @@+---+name: godot-shaders+description: >+ Write Godot 4.x shaders in the Godot Shading Language: canvas_item shaders for 2D+ and spatial shaders for 3D, with vertex/fragment functions, uniforms (source_color,+ hint_range), TIME/UV animation, and screen-reading via hint_screen_texture. Use+ when authoring .gdshader files, writing fragment/vertex code, making 2D/3D visual+ effects, or porting 3.x shaders (SCREEN_TEXTURE, hint_color) to 4.x.+license: Apache-2.0+compatibility: Godot 4.3+ (Godot Shading Language)+metadata:+ engine: godot+ category: godot+ difficulty: advanced+---++# Godot Shaders (4.x)++Write `canvas_item` (2D) and `spatial` (3D) shaders in the Godot Shading Language, animate+with `TIME`/`UV`, expose `uniform`s, and read the screen. Targets **Godot 4.3+**.++## When to use++- Use when writing `.gdshader` code or a `ShaderMaterial`: 2D effects (outline, dissolve,+ flash, water), 3D surface shaders (rim light, toon, scrolling UV), or screen-space+ post effects.++**When *not* to use:** the cross-engine *concepts* of shading (UVs, vertex/fragment+theory) → `shader-programming`; particles/VFX nodes → general 3D; non-shader visuals.++## Core workflow++1. **Pick the shader type** on the first line: `shader_type canvas_item;` for 2D+ (Sprite2D, TextureRect, anything `CanvasItem`) or `shader_type spatial;` for 3D+ materials. (`particles`, `sky`, `fog` also exist.)+2. **Attach via a `ShaderMaterial`.** Create a `ShaderMaterial`, assign your `.gdshader`,+ and put it on the node's `material`. Uniforms appear in the Inspector.+3. **Write `fragment()`** to set the output: `COLOR` (2D) or `ALBEDO`/`EMISSION`/`ALPHA`+ (3D). Optionally `vertex()` to move geometry and `light()` for custom lighting.+4. **Expose tunables as `uniform`s** with hints (`source_color`, `hint_range`) so they are+ editable and correctly color-managed.+5. **Animate with the built-in `TIME`** and sample textures with `texture(tex, UV)`.+6. **Set uniforms from code** with `material.set_shader_parameter("name", value)`.++## Patterns++### 1. 2D (canvas_item): tint + scrolling UV++```glsl+shader_type canvas_item;++uniform vec4 tint : source_color = vec4(1.0); // source_color = sRGB-correct color+uniform float scroll_speed : hint_range(0.0, 2.0) = 0.3;++void fragment() {+ vec2 uv = UV;+ uv.x += TIME * scroll_speed; // scroll horizontally over time+ COLOR = texture(TEXTURE, uv) * tint; // TEXTURE = the node's texture+}+```++### 2. 2D dissolve using a noise threshold++```glsl+shader_type canvas_item;++uniform sampler2D noise : repeat_enable; // a NoiseTexture2D+uniform float amount : hint_range(0.0, 1.0) = 0.0;++void fragment() {+ vec4 tex = texture(TEXTURE, UV);+ float n = texture(noise, UV).r;+ if (n < amount) {+ discard; // cut the pixel away+ }+ COLOR = tex;+}+```++### 3. 3D (spatial): emissive rim light++```glsl+shader_type spatial;++uniform vec4 base_color : source_color = vec4(0.2, 0.5, 1.0, 1.0);+uniform vec3 rim_color : source_color = vec3(0.6, 0.8, 1.0);+uniform float rim_power : hint_range(0.5, 8.0) = 3.0;++void fragment() {+ ALBEDO = base_color.rgb;+ // VIEW and NORMAL are view-space built-ins; rim is strong at grazing angles.+ float rim = pow(1.0 - dot(NORMAL, VIEW), rim_power);+ EMISSION = rim_color * rim;+}+```++### 4. Screen-reading post effect (4.x hint, not SCREEN_TEXTURE)++```glsl+shader_type canvas_item;++// 4.x: declare the screen as a uniform with hint_screen_texture.+uniform sampler2D screen_tex : hint_screen_texture, filter_linear_mipmap;+uniform float blur : hint_range(0.0, 4.0) = 1.0;++void fragment() {+ vec2 px = SCREEN_PIXEL_SIZE * blur;+ vec4 c = texture(screen_tex, SCREEN_UV);+ c += texture(screen_tex, SCREEN_UV + vec2(px.x, 0.0));+ c += texture(screen_tex, SCREEN_UV - vec2(px.x, 0.0));+ COLOR = c / 3.0;+}+```++Set a uniform from GDScript:++```gdscript+$Sprite2D.material.set_shader_parameter("amount", 0.7)+```++## Pitfalls++- **3.x → 4.x renames.** `SCREEN_TEXTURE` is removed — declare+ `uniform sampler2D x : hint_screen_texture;` and sample with `SCREEN_UV`. Color hints+ `hint_color`→`source_color`; `hint_albedo`/`hint_white`→`source_color`;+ `hint_range` stays. Depth/normal use `hint_depth_texture` / `hint_normal_roughness_texture`.+- **Wrong output variable.** In `canvas_item` write `COLOR`; in `spatial` write `ALBEDO`+ (and `EMISSION`, `ALPHA`, `ROUGHNESS`, `METALLIC`). Writing `COLOR` in a spatial shader+ does nothing.+- **Color uniforms without `source_color`** are treated as raw linear values and look+ wrong (washed/dark) because Godot won't sRGB-convert them.+- **Transparency needs opt-in (3D).** For `ALPHA < 1.0` to blend, add a render mode or set+ the material transparency; otherwise it's opaque/cut.+- **Sampling outside [0,1] UV** without `repeat_enable` clamps. Add `: repeat_enable` to+ the sampler uniform for tiling/scroll.+- **`TIME` is seconds since start** and keeps growing — wrap with `fract()`/`mod()` for+ periodic effects to avoid precision drift.+- **`discard` is costly** on some hardware and breaks early-Z; prefer setting `ALPHA`/+ `COLOR.a` when you can.++## References++- For built-in variables per shader type, render modes, `varying`, custom `light()`,+ `vertex()` displacement, and the visual shader graph, read+ `references/shading-language.md`.++## Related skills++- `shader-programming` — engine-agnostic shader concepts (GLSL/HLSL).+- `godot-3d-essentials` — materials, environment, and where spatial shaders live.+- `godot-ui-control` — applying shaders to UI for effects.diff --git a/skills/godot/godot-shaders/references/shading-language.md b/skills/godot/godot-shaders/references/shading-language.mdnew file mode 100644index 0000000..15251bd--- /dev/null+++ b/skills/godot/godot-shaders/references/shading-language.md@@ -0,0 +1,101 @@+# Godot Shading Language reference (Godot 4.3+)++Depth companion to `godot-shaders`. The language is GLSL-like with engine built-ins.++## Shader types and processor functions++| `shader_type` | Used by | Main functions | Key output writes |+|---------------|---------|----------------|-------------------|+| `canvas_item` | 2D `CanvasItem` materials | `vertex`, `fragment`, `light` | `COLOR` |+| `spatial` | 3D `Mesh`/surface materials | `vertex`, `fragment`, `light` | `ALBEDO`, `EMISSION`, `ALPHA`, `ROUGHNESS`, `METALLIC`, `NORMAL_MAP` |+| `particles` | `GPUParticles` process | `start`, `process` | `VELOCITY`, `TRANSFORM`, `COLOR` |+| `sky` | `Sky` material | `sky` | `COLOR` |+| `fog` | `FogVolume` | `fog` | `DENSITY`, `ALBEDO`, `EMISSION` |++## Common built-ins++canvas_item: `UV`, `COLOR`, `TEXTURE`, `TEXTURE_PIXEL_SIZE`, `SCREEN_UV`,+`SCREEN_PIXEL_SIZE`, `VERTEX`, `TIME`, `POINT_COORD`, `MODELVIEW_MATRIX`.++spatial: `VERTEX` (model/local), `NORMAL`, `TANGENT`, `UV`, `UV2`, `VIEW`, `ALBEDO`,+`ALPHA`, `EMISSION`, `ROUGHNESS`, `METALLIC`, `SPECULAR`, `NORMAL_MAP`, `TIME`,+`CAMERA_POSITION_WORLD`, `MODEL_MATRIX`, `VIEW_MATRIX`, `PROJECTION_MATRIX`, `FRAGCOORD`.++## Uniform hints (4.x)++```glsl+uniform float speed : hint_range(0.0, 1.0) = 0.5;+uniform float gain : hint_range(0.0, 2.0, 0.01); // min, max, step+uniform vec4 col : source_color = vec4(1.0); // sRGB color picker+uniform sampler2D tex : source_color, filter_linear_mipmap, repeat_enable;+uniform sampler2D screen_tex : hint_screen_texture, filter_linear_mipmap;+uniform sampler2D depth_tex : hint_depth_texture;+uniform sampler2D normal_rough : hint_normal_roughness_texture;+group_uniforms Movement; // Inspector grouping+uniform float amplitude = 1.0;+```++Sampler filter/repeat qualifiers: `filter_nearest`, `filter_linear`,+`filter_nearest_mipmap`, `filter_linear_mipmap`, `repeat_enable`, `repeat_disable`.++Set from code: `material.set_shader_parameter("name", value)`;+read with `get_shader_parameter("name")`.++## Render modes++First-line modifiers after the type, comma-separated:++- spatial: `unshaded`, `cull_disabled`, `cull_front`, `depth_draw_opaque`,+ `depth_test_disabled`, `blend_add`, `blend_mul`, `diffuse_toon`, `specular_toon`,+ `world_vertex_coords`, `vertex_lighting`, `shadows_disabled`, `ambient_light_disabled`.+- canvas_item: `blend_mix` (default), `blend_add`, `blend_sub`, `blend_mul`,+ `blend_premul_alpha`, `unshaded`, `light_only`.++```glsl+shader_type spatial;+render_mode unshaded, cull_disabled;+```++## varying (pass data vertex -> fragment)++```glsl+varying vec3 world_pos;+void vertex() { world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; }+void fragment() { ALBEDO = fract(world_pos); }+```++## vertex() displacement++```glsl+void vertex() {+ VERTEX.y += sin(VERTEX.x * 4.0 + TIME * 2.0) * 0.1; // wave the mesh+}+```++## Custom light() (toon ramp example, spatial)++```glsl+void light() {+ float ndl = dot(NORMAL, LIGHT);+ float ramp = step(0.0, ndl); // hard two-tone+ DIFFUSE_LIGHT += ALBEDO * LIGHT_COLOR.rgb * ramp * ATTENUATION;+}+```++## 2D normal maps++For lit 2D, write `NORMAL_MAP` in a `canvas_item` fragment (or assign a normal map on the+node) and add a `Light2D`/`PointLight2D` to the scene; `light()` controls the response.++## Visual shaders++`VisualShader` lets you build the same graphs node-by-node and exports to this language.+Useful for iteration; the generated code is standard Godot Shading Language. Convert to a+text `.gdshader` when you need precise control or version it in source.++## Performance notes++- Texture fetches and `discard` are the most expensive common operations; minimize both.+- Branch on uniforms (constant per draw) is cheap; branch on per-pixel values can be slow.+- Precompute in `vertex()` and pass via `varying` when a value is linear across a triangle.+- Prefer `mix()`, `step()`, `smoothstep()`, `clamp()` over `if` for per-pixel selection.diff --git a/skills/godot/godot-ui-control/SKILL.md b/skills/godot/godot-ui-control/SKILL.mdnew file mode 100644index 0000000..8ab3e7a--- /dev/null+++ b/skills/godot/godot-ui-control/SKILL.md@@ -0,0 +1,131 @@+---+name: godot-ui-control+description: >+ Build Godot 4.x user interfaces with Control nodes: anchors and offsets for+ responsive layout, Container nodes (VBox/HBox/Grid/Margin) for automatic+ arrangement, Theme resources for consistent styling, and keyboard/gamepad focus+ navigation. Use when laying out a HUD, menu, or UI in a Godot project, working+ with Control/Container nodes, anchors, themes, or focus in a .tscn.+license: Apache-2.0+compatibility: Godot 4.3++metadata:+ engine: godot+ category: godot+ difficulty: intermediate+---++# Godot UI / Control nodes (4.x)++Lay out responsive UI with `Control` anchors and `Container` nodes, style it with a+`Theme`, and make it navigable by keyboard and gamepad. Targets **Godot 4.3+**.++## When to use++- Use when building HUDs, menus, inventories, dialog boxes, or settings screens with+ `Control`-derived nodes; arranging UI that adapts to window size; theming; or wiring+ focus navigation for controller/keyboard.++**When *not* to use:** in-world 2D nodes (`Node2D`/sprites) → `godot-nodes-scenes`;+animating UI transitions → `godot-animation` (Tween); genre UIs like card hands →+`card-game`/`visual-novel`. For full input rebinding → `input-systems`.++## Core workflow++1. **Use `Control` nodes for UI**, not `Node2D`. Controls have a rect (position + size),+ anchors, and participate in focus/theming.+2. **Anchor for responsiveness.** Anchors are fractions (0–1) of the parent rect that the+ Control's edges stick to. Use the editor's **Layout** presets (Top-Left, Full Rect,+ Center, etc.) instead of hand-placing pixels.+3. **Let Containers position children.** Put children in a `VBoxContainer`,+ `HBoxContainer`, `GridContainer`, `MarginContainer`, etc. — the container sets their+ position/size; you control flow with `size_flags`. Don't set child anchors inside a+ container (it overrides them).+4. **Style with a `Theme`.** Assign a `Theme` resource on a top Control; children inherit+ it. Override per-node with theme overrides only when necessary.+5. **Wire focus** so gamepad/keyboard can move between buttons; set a default focused+ control and define neighbors or rely on auto-neighbor.+6. **Connect signals** (`pressed`, `toggled`, `text_submitted`, `value_changed`).++## Patterns++### 1. Responsive layout with anchors (code form)++```gdscript+extends Control++func _ready() -> void:+ # Stretch this panel to fill its parent (equivalent to the "Full Rect" preset).+ anchors_preset = Control.PRESET_FULL_RECT+ # Or set anchors manually: all four edges at the parent's far corners.+ # anchor_left = 0; anchor_top = 0; anchor_right = 1; anchor_bottom = 1+```++### 2. A menu built from containers + button signals++```gdscript+extends VBoxContainer # children stack vertically, auto-sized++func _ready() -> void:+ for child in get_children():+ if child is Button:+ child.pressed.connect(_on_button_pressed.bind(child.name))+ # Give the first button focus so a gamepad can navigate immediately.+ if get_child_count() > 0:+ (get_child(0) as Control).grab_focus()++func _on_button_pressed(which: StringName) -> void:+ match which:+ "PlayButton": get_tree().change_scene_to_file("res://game.tscn")+ "QuitButton": get_tree().quit()+```++### 3. Size flags: make one child expand to fill leftover space++```gdscript+# In a HBoxContainer: a label on the left, a spacer that eats remaining width.+func _ready() -> void:+ $Label.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN+ $Spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL # grows to fill+```++### 4. Theme override for one node (without a full Theme resource)++```gdscript+func _ready() -> void:+ # Per-node overrides: use add_theme_* (type-specific setters).+ $Title.add_theme_font_size_override("font_size", 32)+ $Title.add_theme_color_override("font_color", Color.GOLD)+ $Panel.add_theme_stylebox_override("panel", preload("res://ui/panel.stylebox.tres"))+```++## Pitfalls++- **Mixing manual position with Containers.** A child of a `Container` cannot set its own+ position/anchors — the container owns layout. To free-place, take the node out of the+ container or use a plain `Control`/`PanelContainer` wrapper.+- **Anchors vs offsets.** Anchors are fractions of the parent; offsets are pixel deltas+ from the anchored point. Set anchors via presets, then nudge with offsets. Setting only+ position while anchors are at 0 makes UI not scale with the window.+- **`Node2D` for UI.** Buttons/labels parented under a `Node2D` won't theme or take focus+ correctly. Keep UI under a `CanvasLayer`/`Control` subtree.+- **Focus lost on gamepad.** If nothing is focused, directional input does nothing. Call+ `grab_focus()` on an initial control and ensure `focus_mode` is not `FOCUS_NONE`.+- **Theme vs theme override.** A `Theme` resource styles a whole subtree; `add_theme_*`+ overrides one node. Overusing per-node overrides defeats centralized theming.+- **`rect_*` properties are renamed.** Godot 3's `rect_size`/`rect_position`/`rect_min_size`+ are now `size`/`position`/`custom_minimum_size` in 4.x.+- **`mouse_filter`** on a full-rect Control can swallow clicks meant for nodes beneath it;+ set `MOUSE_FILTER_IGNORE` on purely decorative panels.++## References++- For the anchor/offset math, every Container type, building/extending Theme and StyleBox+ resources, focus neighbor wiring, and `CanvasLayer` for HUDs, read+ `references/layout-and-theming.md`.++## Related skills++- `godot-animation` — Tween-based UI transitions and juicing.+- `godot-signals-groups` — connecting UI events to game logic.+- `input-systems` — rebindable input and multi-device focus.+- `card-game` / `visual-novel` — UI-heavy genre templates.diff --git a/skills/godot/godot-ui-control/references/layout-and-theming.md b/skills/godot/godot-ui-control/references/layout-and-theming.mdnew file mode 100644index 0000000..6c7ccaf--- /dev/null+++ b/skills/godot/godot-ui-control/references/layout-and-theming.md@@ -0,0 +1,105 @@+# Control layout & theming reference (Godot 4.3+)++Depth companion to `godot-ui-control`.++## Anchors and offsets++A `Control` has four anchors (`anchor_left/top/right/bottom`), each a fraction `0.0–1.0`+of the parent's rect, and four offsets (`offset_left/top/right/bottom`) in pixels from the+anchored point.++- Anchors at `(0,0,0,0)` → the control's edges all track the parent's top-left; size is+ driven entirely by offsets (fixed pixel size, top-left aligned).+- Anchors at `(0,0,1,1)` (Full Rect) → edges track each corner; the control resizes with+ the parent. Offsets become margins.+- Center presets set anchors to `0.5` and use offsets relative to the center.++Use `anchors_preset = Control.PRESET_*` (CENTER, FULL_RECT, TOP_WIDE, BOTTOM_RIGHT, ...)+or the editor's Layout toolbar; it sets anchors and offsets together.++## Container types++| Container | Arranges children |+|-----------|-------------------|+| `VBoxContainer` / `HBoxContainer` | Stacked vertically / horizontally |+| `GridContainer` | Grid with `columns` |+| `MarginContainer` | Adds margins (theme constants `margin_*`) |+| `CenterContainer` | Centers a single child at its min size |+| `PanelContainer` | Draws a panel stylebox behind one child |+| `ScrollContainer` | Scrolls oversized content |+| `TabContainer` | Tabbed pages |+| `AspectRatioContainer` | Keeps child aspect ratio |+| `SplitContainer` (H/V) | Draggable splitter between two children |+| `FlowContainer` (H/V) | Wraps children like text |++Containers ignore child anchors/positions and instead use **size flags**.++## Size flags++```gdscript+size_flags_horizontal / size_flags_vertical:+ SIZE_FILL # fill assigned space+ SIZE_EXPAND # claim extra space (combine with FILL: SIZE_EXPAND_FILL)+ SIZE_SHRINK_BEGIN # shrink to min, align to start+ SIZE_SHRINK_CENTER # shrink to min, centered+ SIZE_SHRINK_END # shrink to min, align to end+size_flags_stretch_ratio = 2.0 # relative share of expand space among siblings+```++## Theme and StyleBox++A `Theme` resource maps (control type, property name) → value. Property kinds: `color`,+`constant`, `font`, `font_size`, `icon`, `stylebox`.++```gdscript+var theme := Theme.new()+theme.set_color("font_color", "Button", Color.WHITE)+theme.set_font_size("font_size", "Button", 18)+var sb := StyleBoxFlat.new()+sb.bg_color = Color(0.1, 0.1, 0.15)+sb.set_corner_radius_all(8)+sb.set_content_margin_all(12)+theme.set_stylebox("normal", "Button", sb)+control.theme = theme # inherited by the whole subtree+```++Per-node overrides (win over the inherited Theme):++```gdscript+add_theme_color_override("font_color", Color.RED)+add_theme_font_size_override("font_size", 24)+add_theme_stylebox_override("panel", my_stylebox)+add_theme_constant_override("separation", 16) # e.g. VBox spacing+remove_theme_color_override("font_color")+```++`StyleBoxFlat` (solid color, borders, corners, shadows), `StyleBoxTexture` (9-patch+texture), and `StyleBoxEmpty` cover most needs.++## Focus navigation (keyboard / gamepad)++```gdscript+control.focus_mode = Control.FOCUS_ALL # FOCUS_NONE | FOCUS_CLICK | FOCUS_ALL+control.grab_focus()+# Explicit neighbors (NodePaths) override automatic geometry-based neighbor finding:+control.focus_neighbor_bottom = next_button.get_path()+control.focus_next = other.get_path() # Tab order+```++The default UI input actions (`ui_up/down/left/right/accept/cancel/focus_next`) drive+focus movement; they map to arrow keys, Enter, and the gamepad D-pad/face buttons out of+the box.++## HUDs over the game++Put HUD UI under a `CanvasLayer` so it renders on top of and independent from the moving+game camera. A `Control` set to Full Rect inside the CanvasLayer fills the viewport+regardless of world scrolling.++## Common signals++- `Button.pressed`, `Button.toggled(toggled_on)`, `Button.button_down/up`.+- `LineEdit.text_submitted(text)`, `text_changed(text)`.+- `Slider/SpinBox.value_changed(value)`.+- `ItemList.item_selected(index)`, `OptionButton.item_selected(index)`.+- `Control.gui_input(event)` for custom click/drag handling.