actions-and-utilities
Use this skill when working with Phaser 4 utility functions, actions, alignment, grid layout, or batch operations on game objects. Triggers on: align, grid…
Use this skill when drawing shapes and graphics in Phaser 4. Covers the Graphics game object, lines, rectangles, circles, arcs, polygons, gradients, fill, stroke, and generated textures. Triggers on: Graphics, draw shape, fillRect, lineStyle, polygon, arc.
$ npx -y skills add phaserjs/phaser --skill graphics-and-shapes --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/graphics-and-shapesContext preview
The summary Claude sees to decide when to auto-load this skill.
Use this skill when drawing shapes and graphics in Phaser 4. Covers the Graphics game object, lines, rectangles, circles, arcs, polygons, gradients, fill, stroke, and generated textures. Triggers on: Graphics, draw shape, fillRect, lineStyle, polygon, arc.
name: graphics-and-shapes description: "Use this skill when drawing shapes and graphics in Phaser 4. Covers the Graphics game object, lines, rectangles, circles, arcs, polygons, gradients, fill, stroke, and generated textures. Triggers on: Graphics, draw shape, fillRect, lineStyle, polygon, arc."
> Drawing primitives with the Graphics game object, and using Shape game objects (Arc, Curve, Ellipse, Grid, IsoBox, IsoTriangle, Line, Polygon, Rectangle, Star, Triangle).
Related skills: sprites-and-images.md, game-object-components.md
---
// Draw a filled rectangle and stroked circle with Graphics const gfx = this.add.graphics(); gfx.fillStyle(0x00aa00, 1); gfx.fillRect(50, 50, 200, 100); gfx.lineStyle(3, 0xff0000, 1); gfx.strokeCircle(400, 150, 60);
// Same shapes as standalone Shape game objects const rect = this.add.rectangle(150, 100, 200, 100, 0x00aa00); const circle = this.add.circle(400, 150, 60); circle.setStrokeStyle(3, 0xff0000);
---
Phaser offers two approaches for rendering primitives without textures.
Created with `this.add.graphics()`. An imperative drawing surface — you call methods like `fillRect`, `strokeCircle`, `beginPath`/`lineTo`/`strokePath` to build up a command buffer that replays each frame.
Individual game objects (Arc, Rectangle, Star, etc.) extending the base `Shape` class. Each renders one predefined geometric shape with precomputed path data.
**When to use which:**
---
const gfx = this.add.graphics();
// Solid fill — call before any fill* method
gfx.fillStyle(0xff0000, 1); // (color, alpha)
// Line style — call before any stroke* method
gfx.lineStyle(4, 0x00ff00, 1); // (width, color, alpha)
// Gradient fill (WebGL only) — 4 corner colors
gfx.fillGradientStyle(
0xff0000, 0x00ff00, 0x0000ff, 0xffff00, // tl, tr, bl, br colors
1, 1, 1, 1 // tl, tr, bl, br alphas
);
gfx.fillRect(0, 0, 300, 200);
// Gradient line style (WebGL only)
gfx.lineGradientStyle(2, 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 1);const gfx = this.add.graphics(); // Rectangles gfx.fillStyle(0x0000ff); gfx.fillRect(x, y, width, height); gfx.lineStyle(2, 0xffffff); gfx.strokeRect(x, y, width, height); // Circles gfx.fillCircle(x, y, radius); gfx.strokeCircle(x, y, radius); // Ellipses gfx.fillEllipse(x, y, width, height, smoothness); gfx.strokeEllipse(x, y, width, height, smoothness); // smoothness defaults to 32 // Triangles gfx.fillTriangle(x0, y0, x1, y1, x2, y2); gfx.strokeTriangle(x0, y0, x1, y1, x2, y2); // Points (draws a small square) gfx.fillPoint(x, y, size); // size defaults to 1 // Lines gfx.lineBetween(x1, y1, x2, y2);
const gfx = this.add.graphics();
// Uniform radius (default 20)
gfx.fillStyle(0x333333);
gfx.fillRoundedRect(50, 50, 300, 200, 16);
gfx.lineStyle(2, 0xffffff);
gfx.strokeRoundedRect(50, 50, 300, 200, 16);
// Per-corner radius
gfx.fillRoundedRect(50, 50, 300, 200, {
tl: 20, tr: 20, bl: 0, br: 0
});
// Concave corners (negative values)
gfx.fillRoundedRect(50, 50, 300, 200, { tl: -10, tr: -10, bl: -10, br: -10 });const gfx = this.add.graphics(); // Manual path gfx.lineStyle(3, 0xffff00); gfx.beginPath(); gfx.moveTo(100, 100); gfx.lineTo(200, 50); gfx.lineTo(300, 100); gfx.lineTo(250, 200); gfx.closePath(); gfx.strokePath(); // or gfx.stroke() — alias for strokePath // Fill a path gfx.fillStyle(0x00aaff); gfx.beginPath(); gfx.moveTo(100, 100); gfx.lineTo(200, 50); gfx.lineTo(300, 100); gfx.closePath(); gfx.fillPath(); // or gfx.fill() — alias for fillPath // Arc within a path (angles in radians) gfx.beginPath(); gfx.arc(200, 200, 80, 0, Math.PI / 2, false, 0); // (x, y, radius, startAngle, endAngle, anticlockwise, overshoot) gfx.strokePath(); // Pie slice gfx.slice(200, 200, 80, 0, Math.PI / 3, false); // auto begins/closes path gfx.fillPath(); // Stroke/fill from point arrays gfx.strokePoints(points, closeShape, closePath, endIndex); gfx.fillPoints(points, closeShape, closePath, endIndex);
Graphics has convenience methods that
Phaser is a fast, free, and fun open source HTML5 game framework that offers WebGL and Canvas rendering across desktop and mobile web browsers and has been actively developed for over 13 years.
Repo: phaserjs/phaser
Use this skill when working with Phaser 4 utility functions, actions, alignment, grid layout, or batch operations on game objects. Triggers on: align, grid…
Use this skill when creating or controlling sprite animations in Phaser 4. Covers spritesheets, atlases, AnimationManager, AnimationState, play/stop/chain,…
Use this skill when adding audio or sound to a Phaser 4 game. Covers loading audio, playing sounds, music, volume, spatial audio, Web Audio API, and…
Use this skill when working with cameras in Phaser 4. Covers camera effects (shake, fade, flash, pan, zoom), following sprites, scroll, bounds, viewports,…
Use this skill when working with curves and paths in Phaser 4. Covers splines, bezier curves, lines, ellipses, path followers, and mathematical curve types.…
Use this skill when using the Phaser 4 DataManager to store custom key-value data on game objects, listen for data change events, or manage game state.…