Pixijs Scene Graphics 标志

Pixijs Scene Graphics

组织
pixijs
pixijs-scene-graphics

在您需要在 PixiJS v8 中绘制矢量形状和路径时使用此技能。涵盖 Graphics API:先定义形状再填充的方法(rect/circle/ellipse/poly/roundRect/star/regularPoly/roundPoly/roundShape/filletRect/chamferRect)、路径方法(moveTo/lineTo/bezierCurveTo/quadraticCurveTo/arc/arcTo/arcToSvg/closePath)、fill/stroke/cut、孔洞、FillGradient(线性/径向)、FillPattern、GraphicsContext 共享、SVG 导入/导出、containsPoint 命中测试、克隆、清除、边界、fillStyle/strokeStyle、绘制时变换(rotateTransform/scaleTransform/translateTransform/setTransform/save/restore)、默认样式、GraphicsPath 复用。触发词:Graphics、GraphicsContext、rect、circle、poly、roundRect、fill、stroke、cut、hole、beginHole、FillGradient、FillPattern、moveTo、bezierCurveTo、svg、graphicsContextToSvg、svg export、GraphicsOptions、containsPoint、clone、clear、bounds、rotateTransform、translateTransform、setFillStyle、setStrokeStyle、GraphicsPath。

Add to TypingMind

概览

发布者pixijs
代码仓库pixijs-skills
技能名称pixijs-scene-graphics
星标数
357
复刻数
19
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 pixijs 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Pixijs Scene Graphics AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/pixijs/pixijs-skills/tree/main/skills/pixijs-scene-graphics
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/pixijs/pixijs-skills.git /tmp/pixijs-skills
mkdir -p .claude/skills
cp -r /tmp/pixijs-skills/skills/pixijs-scene-graphics .claude/skills/pixijs-scene-graphics
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Pixijs Scene Graphics,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Pixijs Scene Graphics。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Pixijs Scene Graphics 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Graphics is the vector-drawing leaf of the PixiJS v8 scene graph. The v8 API follows a shape-then-style pattern: draw a shape or path with rect, circle, moveTo, etc., then apply fill and/or stroke. Every method returns this for chaining, and the drawing instructions live on a GraphicsContext that can be shared between instances.

Assumes familiarity with pixijs-scene-core-concepts. Graphics is a leaf: do not nest children inside it. Wrap multiple Graphics objects in a Container to group them.

Quick Start

ts
const g = new Graphics();

g.rect(10, 10, 200, 100)
  .fill({ color: 0x3498db, alpha: 0.8 })
  .stroke({ width: 3, color: 0x2c3e50 });

g.circle(300, 60, 40).fill(0xe74c3c);

g.moveTo(50, 200)
  .lineTo(200, 200)
  .bezierCurveTo(250, 250, 100, 300, 50, 250)
  .closePath()
  .fill(0x6c5ce7);

app.stage.addChild(g);

Related skills: pixijs-scene-core-concepts (scene graph basics), pixijs-scene-container (group graphics with other objects), pixijs-scene-core-concepts/references/masking.md (Graphics as a stencil mask), pixijs-filters (effects), pixijs-performance (batching, cacheAsTexture).

Constructor options

All Container options (position, scale, tint, label, filters, zIndex, etc.) are also valid here — see skills/pixijs-scene-core-concepts/references/constructor-options.md.

Leaf-specific options added by GraphicsOptions:

OptionTypeDefaultDescription
contextGraphicsContextnew GraphicsContext()Shared drawing context. Passing a context reuses its tessellated geometry across multiple Graphics nodes, avoiding duplicate GPU work. If omitted, each Graphics creates and owns a new context.
roundPixelsbooleanfalseRounds the final on-screen x/y to the nearest pixel. Produces crisper lines for pixel-art styles at the cost of smooth sub-pixel movement.

The constructor also accepts a GraphicsContext instance as its sole argument (new Graphics(ctx)), which is shorthand for new Graphics({ context: ctx }).

Core Patterns

Shape-then-fill workflow

ts
const g = new Graphics();

g.rect(10, 10, 200, 100)
  .fill({ color: 0x3498db, alpha: 0.8 })
  .stroke({ width: 3, color: 0x2c3e50 });

g.circle(150, 200, 40).fill(0xe74c3c);
g.roundRect(300, 10, 150, 80, 12).fill(0x2ecc71);
g.poly([0, 0, 60, 0, 30, 50], true).fill(0x9b59b6);
g.star(400, 200, 5, 40, 20, 0).fill(0xf39c12);
g.ellipse(100, 350, 60, 30).fill(0x1abc9c);

fill() accepts a FillInput: a color number/string, { color, alpha, texture, matrix, textureSpace }, a FillGradient, a FillPattern, or a Texture. When filling with a texture, textureSpace controls coordinate mapping:

  • 'local' (default): texture is scaled to fit each shape's bounding box (normalized 0-1 coordinates).
  • 'global': texture position/scale are relative to the Graphics object's coordinate system, shared across all shapes.
  • Atlas sub-textures: 'global' honors the frame origin and rotation, so a shape drawn at the frame's size matches a Sprite of that frame. 'local' maps the whole source image; pass a matrix that targets the frame's region of the source, or renderer.generateTexture() the frame first.

FillInput also supports a nested fill subfield: a FillStyle options object can embed a FillGradient or FillPattern under its fill key, which applies the gradient or pattern alongside the color, alpha, texture, and matrix modifiers on the outer object.

stroke() accepts a color, a FillGradient, a FillPattern, or a StrokeStyle object that combines all FillStyle keys (color, alpha, texture, matrix, fill, textureSpace) with stroke attributes:

AttributeDefaultNotes
width1Pixel width of the stroke.
cap'butt'One of 'butt', 'round', 'square'. End style for open paths.
join'miter'One of 'miter', 'round', 'bevel'. Corner style.
miterLimit10Caps how far miter joins extend before falling back to bevel.
alignment0.51 = inside the shape, 0.5 = centered, 0 = outside.
pixelLinefalseAligns 1-pixel lines to the pixel grid for crisp output. Graphics-only.

Strokes can use the same gradients and patterns as fills via fill: gradient or texture: tex:

ts
const grad = new FillGradient({
  end: { x: 1, y: 0 },
  colorStops: [
    { offset: 0, color: 0xff0000 },
    { offset: 1, color: 0x0000ff },
  ],
});
g.rect(0, 0, 200, 100).stroke({
  width: 8,
  fill: grad,
  join: "round",
  cap: "round",
});

Both fill() and stroke() can be called after the same shape; calling stroke() immediately after fill() reuses the same path.

Advanced shape primitives

ts
g.regularPoly(100, 100, 50, 6, 0).fill(0x3498db);
g.roundPoly(250, 100, 50, 5, 10).fill(0xe74c3c);
g.chamferRect(350, 50, 100, 80, 15).fill(0x2ecc71);
g.filletRect(500, 50, 100, 80, 15).fill(0x9b59b6);
g.roundShape(
  [
    { x: 50, y: 250, radius: 20 },
    { x: 150, y: 250, radius: 5 },
    { x: 150, y: 350, radius: 10 },
    { x: 50, y: 350, radius: 15 },
  ],
  10,
).fill(0xf39c12);

Holes with cut()

ts
g.rect(0, 0, 200, 200).fill(0x00ff00).circle(100, 100, 50).cut();

cut() subtracts the current active path from the previously drawn fill or stroke. Rules:

  • The hole must be completely inside the target shape. Holes that overlap edges or sit outside the shape will not render correctly because the renderer triangulates with the hole as an interior boundary.
  • cut() looks back at up to the last two instructions. When you fill() and then stroke() the same path, a single cut() adds the hole to the stroke first; a second cut() adds it to the fill underneath.
  • After cut(), the active path resets so you can start the next shape with moveTo, rect, etc.
  • cut() applies to strokes too — g.rect(...).stroke(...).circle(...).cut() cuts a hole through the stroke outline.

Punch multiple holes with a single cut() by drawing several shapes into the active path before calling it. Each shape accumulates into the same hole path:

ts
const g = new Graphics();

g.rect(350, 350, 150, 150).fill(0x00ff00);

// Draw three circles into the active path, then cut them all in one call
g.circle(375, 375, 25);
g.circle(425, 425, 25);
g.circle(475, 475, 25);
g.cut();

If you need holes on separate filled shapes, give each shape its own fill() and matching cut():

ts
g.rect(0, 0, 100, 100).fill(0x3498db);
g.circle(50, 50, 20).cut(); // hole in the rect

g.rect(120, 0, 100, 100).fill(0xe74c3c);
g.circle(170, 50, 20).cut(); // hole in the second rect

Calling cut() on a shape that already has a hole adds to the existing hole path rather than replacing it. Use this to layer holes additively.

Paths and complex shapes

ts
g.moveTo(50, 50)
  .lineTo(200, 50)
  .bezierCurveTo(250, 100, 250, 150, 200, 200)
  .quadraticCurveTo(100, 250, 50, 200)
  .closePath()
  .fill({ color: 0x6c5ce7, alpha: 0.7 })
  .stroke({ width: 2, color: 0xdfe6e9 });

Path methods: moveTo, lineTo, bezierCurveTo, quadraticCurveTo, arc, arcTo, arcToSvg, closePath. Call beginPath() to discard the current path and start a new one.

ts
// arc(cx, cy, radius, startAngle, endAngle, counterclockwise?)
g.moveTo(80, 50)
  .arc(50, 50, 30, 0, Math.PI)
  .stroke({ width: 4, color: 0x2c3e50 });

// arcTo(x1, y1, x2, y2, radius) — rounded corner between two line segments
g.moveTo(150, 20)
  .arcTo(200, 20, 200, 80, 20)
  .lineTo(200, 80)
  .stroke({ width: 2 });

// arcToSvg(rx, ry, xAxisRotation, largeArcFlag, sweepFlag, x, y) — matches the SVG `A` command
g.moveTo(250, 50).arcToSvg(40, 20, 0, 1, 0, 330, 50).stroke({ width: 2 });

Gradients and patterns

ts
// Linear gradient
const linear = new FillGradient({
  end: { x: 1, y: 0 },
  colorStops: [
    { offset: 0, color: 0xff0000 },
    { offset: 1, color: 0x0000ff },
  ],
});
g.rect(0, 0, 200, 100).fill(linear);

// Radial gradient. Coordinates are normalized 0-1 in the default "local" space:
// inner circle at the center, outer circle reaching the edges.
const radial = new FillGradient({
  type: "radial",
  center: { x: 0.5, y: 0.5 },
  innerRadius: 0,
  outerCenter: { x: 0.5, y: 0.5 },
  outerRadius: 0.5,
  colorStops: [
    { offset: 0, color: 0xffffff },
    { offset: 1, color: 0x000000 },
  ],
});
g.circle(100, 100, 100).fill(radial);

// Pixel coordinates need textureSpace: "global"; the gradient then spans shapes.
const shared = new FillGradient({
  type: "radial",
  center: { x: 100, y: 100 },
  outerRadius: 100,
  textureSpace: "global",
  colorStops: [
    { offset: 0, color: 0xffffff },
    { offset: 1, color: 0x000000 },
  ],
});
g.rect(0, 0, 200, 200).fill(shared);

const brick = await Assets.load("brick.png");

// Options-object form (preferred)
const pattern = new FillPattern({
  texture: brick,
  repetition: "repeat", // 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat'
  textureSpace: "global", // 'global' (default) | 'local'
});

// Legacy positional form is still supported
const pattern2 = new FillPattern(brick, "repeat");

g.rect(0, 120, 200, 100).fill(pattern);

FillGradient's default type is 'linear' with start {0,0} to end {0,1} (vertical). Set type: 'radial' with center/innerRadius and outerCenter/outerRadius for radial gradients; rotation (radians, default 0) and scale (default 1) make it elliptical and apply to Graphics only. textureSpace defaults to 'local' (normalized 0-1 shape coordinates); use 'global' for pixel coordinates shared across shapes.

FillPattern takes an options object ({ texture, repetition?, textureSpace? }) or the legacy positional form (new FillPattern(texture, repetition?)). repetition selects the tiling mode. textureSpace controls how tiles map to shapes:

  • 'global' (default): tiles repeat continuously across the Graphics coordinate system, so adjacent shapes share one tiling grid. Best for backgrounds and seamless textures.
  • 'local': a single tile fits each shape's bounds. Combine with setTransform to subdivide a shape into a tile grid.

Note FillPattern defaults textureSpace to 'global', unlike the 'local' default for texture fills shown above.

setTransform(matrix) copies the given matrix directly onto the pattern transform to scale, rotate, or offset the tiling; call setTransform() with no argument to reset to identity.

Set textureSpace and the transform on the FillPattern itself. When a pattern is passed inside a style object (fill({ fill: pattern, textureSpace: "local" })), the pattern's own values replace the style's textureSpace and matrix.

Drawing a texture directly

ts
const tex = await Assets.load("icon.png");

// Draw the whole texture at (x, y) with optional tint
g.texture(tex, 0xffffff, 20, 20);

// Draw a subregion (dx, dy, dw, dh)
g.texture(tex, 0xff0000, 100, 20, 64, 64);

Graphics.texture(texture, tint?, dx?, dy?, dw?, dh?) is a shortcut for drawing a single textured rect without going through fill(). Useful for icons where you don't need the full sprite lifecycle.

GraphicsContext sharing

ts
const ctx = new GraphicsContext().rect(0, 0, 50, 50).fill(0xff0000);

const g1 = new Graphics(ctx);
const g2 = new Graphics(ctx);
g2.x = 100;

Context sharing avoids duplicate GPU geometry; the expensive tessellation runs once. You can also assign a context after construction: g.context = existingContext.

SVG import and export

Parse SVG markup into the active context with svg():

ts
g.svg(`<svg viewBox="0 0 100 100">
    <circle cx="50" cy="50" r="40" fill="red"/>
</svg>`);

svg() parses <path> (with fill-rule="evenodd" holes), <rect>, <circle>, <ellipse>, <line>, <polygon>, <polyline>, and <g> grouping. Styling comes from fill, stroke, stroke-width, fill-opacity, stroke-opacity, and opacity, as attributes or inline style. <linearGradient> and <radialGradient> definitions in <defs> become FillGradients applied through url(#id); gradientUnits maps to textureSpace and percentage coordinates are accepted. Not supported: transform attributes, <style> blocks, stroke-linecap/stroke-linejoin/stroke-dasharray, gradientTransform, spreadMethod, stop-opacity, <text>, <image>, <use>, <clipPath>, <mask>, <pattern>. Unsupported elements log a warning and are skipped. Complex hole geometries may render inaccurately because Pixi's triangulation is performance-optimized.

Serialize a Graphics or GraphicsContext back to a self-contained SVG document string with graphicsContextToSvg:

ts
import { Graphics, graphicsContextToSvg } from "pixi.js";

const g = new Graphics()
  .rect(0, 0, 100, 50)
  .fill({ color: 0xff0000 })
  .circle(150, 25, 25)
  .stroke({ color: 0x0000ff, width: 4 });

const svgString = graphicsContextToSvg(g, 2);

graphicsContextToSvg(source, precision = 2) is a pure function that reads the context's instructions and returns a complete <svg> string with an auto-computed viewBox. Pass a Graphics or a GraphicsContext; precision controls decimal places on emitted coordinates. Exports every shape-then-fill primitive (advanced ones like regularPoly/filletRect fall back to a shape-path), all path methods, stroke attributes (width, cap, join, miterLimit), fill-opacity/stroke-opacity, and FillGradient (linear and radial) via a <defs> block. Holes collapse into one <path> with fill-rule="evenodd". FillPattern and texture fills have no SVG equivalent: patterns fall through to the fill's solid color, and texture() instructions are skipped entirely. Exported markup roundtrips back through g.svg(...) without cleanup, so you can export, store, and later reimport a shape into another Graphics.

Reusing a GraphicsPath

ts
const arrow = new GraphicsPath()
  .moveTo(0, 0)
  .lineTo(40, 0)
  .lineTo(40, -10)
  .lineTo(60, 10)
  .lineTo(40, 30)
  .lineTo(40, 20)
  .lineTo(0, 20)
  .closePath();

g.path(arrow).fill(0x3498db);
g.translateTransform(80, 0).path(arrow).fill(0xe74c3c);

Graphics.path(graphicsPath) (and GraphicsContext.path()) appends a prebuilt GraphicsPath onto the active path. Build once, draw many times.

Draw-time transforms

Graphics has its own transform stack used while drawing that is separate from the Container transform applied to the rendered output. The drawing methods are renamed to avoid clashing with Container.rotation, Container.scale, Container.position:

Drawing transformContainer transform
g.rotateTransform(angle)g.rotation
g.scaleTransform(x, y?)g.scale.set(x, y)
g.translateTransform(x, y?)g.position.set(x, y)
g.setTransform(matrix) or setTransform(a,b,c,d,tx,ty)g.setFromMatrix(matrix)
g.transform(matrix) or transform(a,b,c,d,tx,ty)n/a
g.getTransform() / g.resetTransform()n/a
ts
const g = new Graphics();

g.translateTransform(100, 100)
  .rotateTransform(Math.PI / 4)
  .rect(-25, -25, 50, 50)
  .fill(0x3498db);

// The square is rotated 45 degrees as it is added to the geometry.
// Setting g.rotation later rotates the entire Graphics on screen.

The drawing transform affects every subsequent shape and path command added to the context. Use save()/restore() to scope it.

State save/restore

ts
g.save();
g.translateTransform(100, 100);
g.rotateTransform(Math.PI / 4);
g.rect(0, 0, 50, 50).fill(0xff0000);
g.restore();

save() pushes the drawing transform, fill style, and stroke style onto a stack; restore() pops them. Graphics exposes save/restore directly, mirroring the underlying GraphicsContext calls.

Default styles via setFillStyle / setStrokeStyle

ts
g.setFillStyle({ color: 0x3498db, alpha: 0.8 }).setStrokeStyle({
  width: 2,
  color: 0x2c3e50,
});

g.rect(0, 0, 100, 100).fill().stroke();
g.circle(150, 50, 40).fill().stroke();

setFillStyle() and setStrokeStyle() configure the default style used by subsequent fill() / stroke() calls when no argument is passed. Read or replace the current style at any time via the fillStyle and strokeStyle getters/setters. Override the library-wide defaults by mutating GraphicsContext.defaultFillStyle and GraphicsContext.defaultStrokeStyle once at startup.

Hit testing

ts
const g = new Graphics().star(100, 100, 5, 60, 30).fill(0xf39c12);
g.eventMode = "static";
g.on("pointermove", (e) => {
  if (g.containsPoint(g.toLocal(e.global))) {
    /* over the star, not just its bbox */
  }
});

Graphics.containsPoint(pointInLocalSpace) runs a topology-aware test against every filled and stroked shape in the context, including holes. Convert global pointer coordinates with toLocal() first. Stroked shapes hit-test against the drawn stroke: the hit band follows the stroke's width and alignment (1 inside, 0.5 centered, 0 outside), independent of the polygon's winding order.

Cloning, clearing, and bounds

ts
const g = new Graphics().rect(0, 0, 100, 100).fill(0xff0000);

const shallow = g.clone(); // shares the same GraphicsContext
const deep = g.clone(true); // creates an independent context

console.log(g.bounds.width); // 100 - geometry bounds before transforms

g.clear(); // wipes active path, instructions, and transform; fill/stroke styles persist
  • clone() returns a new Graphics that shares the source context (cheap, geometry is reused). Both objects update together if the context changes.
  • clone(true) clones the context as well so the new Graphics can be edited independently.
  • bounds returns the geometry bounds before the Container transform. Useful for layout decisions.
  • clear() resets the context so the same Graphics can be reused. See Common Mistakes below for guidance on when to clear versus when to keep stable geometry.

GraphicsContext utilities

MemberBehavior
ctx.path(graphicsPath)Apply a prebuilt GraphicsPath onto the active path. Reuse one path across many contexts or frames.
ctx.beginPath()Discard the current active path and start a new one without affecting committed instructions.
ctx.setFillStyle(style) / ctx.fillStyleSet or read the default fill style used by subsequent shapes without calling fill().
ctx.setStrokeStyle(style) / ctx.strokeStyleSet or read the default stroke style used by subsequent shapes without calling stroke().
ctx.boundsCached geometry bounds across all fill/stroke/texture instructions.
ctx.clear()Wipe instructions, the active path, and the drawing transform.
ctx.clone()Deep copy including instructions, active path, transform, styles, and stack.
ctx.containsPoint(point)Topology-aware hit test against all filled and stroked shapes (including holes).
ctx.batchModeOne of 'auto', 'batch', 'no-batch' — force or disable batching for the shapes in this context.
ctx.customShaderAssign a Shader to override the default graphics shader.
GraphicsContext.defaultFillStyleStatic fallback used when fill() is called without arguments and no fill style is set.
GraphicsContext.defaultStrokeStyleStatic fallback used when stroke() is called without arguments and no stroke style is set.

GraphicsContext is an EventEmitter that emits update, destroy, and unload events. Subscribe via ctx.on('update' | 'destroy' | 'unload', cb) when tooling or pools need to react to context lifecycle changes.

Common Mistakes

[CRITICAL] Using v7 beginFill/drawRect/endFill

Wrong:

ts
const g = new Graphics().beginFill(0xff0000).drawRect(0, 0, 100, 100).endFill();

Correct:

ts
const g = new Graphics().rect(0, 0, 100, 100).fill(0xff0000);

v8 replaced "set style, draw, end" with "draw shape, then apply style". beginFill/endFill do not exist.

[CRITICAL] Using old shape method names

Wrong:

ts
g.drawCircle(50, 50, 25);

Correct:

ts
g.circle(50, 50, 25);

All draw* methods were renamed in v8: drawRect → rect, drawCircle → circle, drawEllipse → ellipse, drawPolygon → poly, drawRoundedRect → roundRect, drawStar → star.

[CRITICAL] Using lineStyle instead of stroke

Wrong:

ts
g.lineStyle(2, 0xffffff);
g.drawRect(0, 0, 100, 100);

Correct:

ts
g.rect(0, 0, 100, 100).stroke({ width: 2, color: 0xffffff });

lineStyle was removed. Use stroke() after drawing the shape. The stroke options object accepts width, color, alpha, cap, join, alignment, miterLimit, and pixelLine.

[HIGH] Using beginHole/endHole for holes

Wrong:

ts
g.beginFill(0x00ff00)
  .drawRect(0, 0, 100, 100)
  .beginHole()
  .drawCircle(50, 50, 20)
  .endHole()
  .endFill();

Correct:

ts
g.rect(0, 0, 100, 100).fill(0x00ff00).circle(50, 50, 20).cut();

beginHole/endHole were replaced by cut(). Draw the outer shape, fill it, then draw the hole shape and call cut().

[HIGH] Using GraphicsGeometry instead of GraphicsContext

Wrong:

ts
const geom = g.geometry;
const clone = new Graphics(geom);

Correct:

ts
const ctx = new GraphicsContext().rect(0, 0, 100, 100).fill(0xff0000);
const g1 = new Graphics(ctx);
const g2 = new Graphics(ctx);

GraphicsGeometry was replaced by GraphicsContext in v8. There is no .geometry property.

[HIGH] Destroying a shared GraphicsContext unexpectedly

ts
const ctx = new GraphicsContext().rect(0, 0, 50, 50).fill(0xff0000);
const g1 = new Graphics(ctx);
const g2 = new Graphics(ctx);

g1.destroy({ context: true }); // g2 is left holding a destroyed context

Destroying a shared GraphicsContext does not destroy the other Graphics using it, but they keep a reference to the now-destroyed context and stop updating or rendering correctly. When passing a context via the constructor, destroy() with no args preserves the context and detaches the instance from it; use destroy({ context: false }) to be explicit. Only destroy the context when all sharing instances are done with it. A self-owned context (not passed via constructor) is still destroyed by destroy() with no args.

[HIGH] Clearing and redrawing Graphics every frame

Graphics are designed to be stable, not dynamic. Calling clear() and redrawing every frame rebuilds GPU geometry each time. For dynamic visuals:

  • Use Sprite with pre-rendered textures and transform changes.
  • Use cacheAsTexture(true) for complex static graphics.
  • For real-time shape changes, consider Mesh with custom geometry updates.

This is the opposite of HTML Canvas 2D, where redrawing each frame is normal. PixiJS tessellates shapes into GPU triangles, so initial draw is expensive but subsequent renders are fast. Treat Graphics more like SVG elements than canvas draw calls.

[MEDIUM] Do not nest children inside a Graphics

Graphics sets allowChildren = false. Adding children logs a deprecation warning and will be a hard error in a future version. Wrap multiple graphics alongside other leaves in a plain Container:

ts
const group = new Container();
group.addChild(graphics, sprite);

API Reference

常见问题

Pixijs Scene Graphics AI 技能有什么作用?

在您需要在 PixiJS v8 中绘制矢量形状和路径时使用此技能。涵盖 Graphics API:先定义形状再填充的方法(rect/circle/ellipse/poly/roundRect/star/regularPoly/roundPoly/roundShape/filletRect/chamferRect)、路径方法(moveTo/lineTo/bezierCurveTo/quadraticCurveTo/arc/arcTo/arcToSvg/closePath)、fill/stroke/cut、孔洞、FillGradient(线性/径向)、FillPattern、GraphicsContext 共享、SVG 导入/导出、containsPoint 命中测试、克隆、清除、边界、fillStyle/strokeStyle、绘制时变换(rotateTransform/scaleTransform/translateTransform/setTransform/save/restore)、默认样式、GraphicsPath 复用。触发词:Graphics、GraphicsContext、rect、circle、poly、roundRect、fill、stroke、cut、hole、beginHole、FillGradient、FillPattern、moveTo、bezier...

为什么在 TypingMind 中使用 Pixijs Scene Graphics?

因为您只需安装一次,就能搭配任何模型使用。Pixijs Scene Graphics 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Pixijs Scene Graphics?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/pixijs/pixijs-skills/tree/main/skills/pixijs-scene-graphics。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Pixijs Scene Graphics?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Pixijs Scene Graphics 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Pixijs Scene Graphics 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Pixijs Scene Graphics AI 技能免费吗?

是的。pixijs 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇