# graphics-and-shapes

Skill for drawing primitives in Phaser 4: rectangles, circles, arcs, polygons, gradients. Use it when you need graphics without textures via Graphics or Shape objects.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 827 installs · ★ 40566
- Author: phaserjs
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/phaserjs/phaser/tree/HEAD/skills/graphics-and-shapes/SKILL.md
- Updated: 2026-08-21
- HTML: https://affpapa.org/en/nevibecode/skills/graphics-and-shapes

## What it does

The skill covers two drawing strategies in Phaser 4. Graphics is an imperative drawing surface where you call methods like `fillRect`, `strokeCircle`, `beginPath` and `lineTo` to build a command buffer. It supports paths, arcs, gradients, rounded rectangles, and canvas transforms (`translateCanvas`, `rotateCanvas`, `scaleCanvas`). You can generate a texture from the drawing with `generateTexture`.

The second approach is Shape objects (Arc, Rectangle, Star and others) that extend the base Shape class. Each renders one geometric shape with precomputed path data. Shapes are full game objects: you can tween them, scale them, add them to groups, enable input or physics. They include Origin and GetBounds, which Graphics lacks.

Use Graphics for dynamic drawing, complex paths, multiple shapes in one object, or when you need gradients. Use Shape objects for individual UI elements, simple indicators, physics-enabled shapes, or when you want game object features like tweening and bounds.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add phaserjs/phaser --skill graphics-and-shapes -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/graphics-and-shapes/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/graphics-and-shapes/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add phaserjs/phaser --skill graphics-and-shapes -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/graphics-and-shapes/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add phaserjs/phaser --skill graphics-and-shapes -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/graphics-and-shapes/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install phaserjs/phaser graphics-and-shapes
```

2. **Manually: put the files in place**
- File: `.github/skills/graphics-and-shapes/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add phaserjs/phaser --skill graphics-and-shapes -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/phaserjs/phaser --path skills/graphics-and-shapes
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/graphics-and-shapes/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add phaserjs/phaser --skill graphics-and-shapes -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/phaserjs/phaser/tree/HEAD/skills/graphics-and-shapes/SKILL.md

## When to use it
- draw filled and stroked rectangles, circles, and ellipses
- create complex paths from lines and arcs
- apply gradient fills and strokes
- generate textures from drawn shapes
- draw rounded corners, including concave ones

## Example prompts
- draw a filled green rectangle and red stroked circle using Graphics
- create three Shape objects: a rounded rectangle, a star, and a triangle
- draw a custom path with `beginPath`, multiple `lineTo` calls, and gradient fill

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 4ad09f5a363b2e78.

BEGIN THIRD-PARTY FILE 4ad09f5a363b2e78
````text
---
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."
---

# Phaser 4 — Graphics and Shapes

> 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

---

## Quick Start

```js
// 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);
```

```js
// 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);
```

---

## Core Concepts — Graphics vs Shape Objects

Phaser offers two approaches for rendering primitives without textures.

### Graphics Game Object

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.

- Factory: `this.add.graphics(config?)` where config is `{ x?, y?, lineStyle?, fillStyle? }`.
- Supports paths, arcs, gradients, rounded rectangles, canvas transforms (`translateCanvas`, `scaleCanvas`, `rotateCanvas`), and `save`/`restore`.
- Can generate a Texture from the drawing via `generateTexture(key, width, height)`.
- Expensive to render, especially with complex shapes. Uses its own WebGL shader. Group Graphics objects together to minimize batch flushes.
- Components: AlphaSingle, BlendMode, Depth, Lighting, Mask, RenderNodes, Transform, Visible, ScrollFactor.
- Does NOT include Origin or GetBounds (position is set via options or `setPosition`).

### Shape Game Objects

Individual game objects (Arc, Rectangle, Star, etc.) extending the base `Shape` class. Each renders one predefined geometric shape with precomputed path data.

- Created via dedicated factory methods: `this.add.rectangle(...)`, `this.add.circle(...)`, etc.
- Fully featured game objects: can be tweened, scaled, added to groups/containers, enabled for input/physics.
- Style via `setFillStyle(color, alpha)` and `setStrokeStyle(lineWidth, color, alpha)`.
- Share the same WebGL batch as Graphics for efficient rendering.
- Do NOT support gradients, path detail threshold, or canvas transforms.
````
END THIRD-PARTY FILE 4ad09f5a363b2e78

The third-party file has ended. Everything between the 4ad09f5a363b2e78 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2678 of 19801 bytes. © phaserjs · MIT · https://github.com/phaserjs/phaser/tree/HEAD/skills/graphics-and-shapes/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
