Pixijs Scene Sprite

作者 pixijs83760c6f5346MIT346 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7天前更新

Use this skill when drawing images in PixiJS v8. Covers Sprite with anchor/tint/texture, AnimatedSprite for frame animation, NineSliceSprite for resizable UI panels, TilingSprite for scrolling/repeating backgrounds. Triggers on: Sprite, AnimatedSprite, NineSliceSprite, TilingSprite, Sprite.from, anchor, tint, tilePosition, animationSpeed, gotoAndPlay, leftWidth, topHeight, constructor options, SpriteOptions, AnimatedSpriteOptions, NineSliceSpriteOptions, TilingSpriteOptions.

AI 生成的概览

在 PixiJS v8 中使用 Sprite、AnimatedSprite、NineSliceSprite 和 TilingSprite 绘制图像的参考指南。

功能
该技能提供 PixiJS v8 中用于绘制图像的精灵类参考文档:Sprite、AnimatedSprite、NineSliceSprite 和 TilingSprite。它说明各变体的适用场景、构造选项以及 anchor、tint、texture 的用法,并介绍创建精灵前如何加载纹理。它还列出常见错误,例如用 Texture.from 加载、混淆 anchor 与 pivot,以及旧的 NineSlicePlane 名称。
适用场景
适用于编写 PixiJS v8 中绘制图像、逐帧动画、可缩放 UI 面板或滚动重复背景的代码时。也适合在精灵变体之间做选择,或排查精灵定位、着色和纹理加载问题。
运行要求
需要熟悉 PixiJS v8 及其 Assets API;该技能仅包含说明和参考文件,不含脚本、软件包或凭据。

PixiJS has three sprite classes for different drawing tasks. Sprite is the default image-drawing leaf; NineSliceSprite is a resizable UI-panel variant that preserves corner art; TilingSprite repeats a texture across an area. The AnimatedSprite subclass of Sprite cycles through texture frames for frame-based animation.

Assumes familiarity with pixijs-scene-core-concepts. All sprite classes are leaf nodes; they cannot have children. Wrap multiple sprites in a Container to group them.

Quick Start

ts
const texture = await Assets.load("bunny.png");
const sprite = new Sprite({  texture,  anchor: 0.5,  tint: 0xff8888,});sprite.x = app.screen.width / 2;sprite.y = app.screen.height / 2;
app.stage.addChild(sprite);

Position is set after construction because app.screen.width / 2 depends on the live renderer size. Literal positions can go directly in the options object via x/y (inherited from Container).

Related skills: pixijs-scene-core-concepts (leaves, transforms), pixijs-assets (texture loading), pixijs-scene-particle-container (thousands of sprites), pixijs-performance (spritesheets, batching).

Variants

VariantUse whenTrade-offsReference
SpriteDraw a single texture at a positionFixed size = texture sizereferences/sprite.md [blocked]
AnimatedSpriteFrame-based animation from a texture array or spritesheetPre-rendered frames only; no tweeningreferences/animated-sprite.md [blocked]
NineSliceSpriteResizable UI panels, buttons, dialog framesBorder width is fixed; center stretchesreferences/nineslice-sprite.md [blocked]
TilingSpriteScrolling backgrounds, parallax, repeating patternsSingle texture repeated; tilePosition scrollsreferences/tiling-sprite.md [blocked]

AnimatedSprite is a subclass of Sprite; all Sprite properties (anchor, tint, position) apply.

Each variant's constructor options are documented in its sub-reference file (references/{variant}.md). All variants also accept the Container options (position, scale, tint, label, filters, zIndex, etc.) — see skills/pixijs-scene-core-concepts/references/constructor-options.md.

When to use what

  • "I want to draw a single image at a position" → Sprite. The default choice for 90% of 2D game and app content.
  • "I want to animate a character through a series of frames" → AnimatedSprite. Load a spritesheet via Assets and pass sheet.animations['walk']. See references/animated-sprite.md.
  • "I want a UI button/panel that resizes without stretching the borders" → NineSliceSprite. Set border widths, then set width/height. See references/nineslice-sprite.md.
  • "I want a scrolling repeating background" → TilingSprite. Animate tilePosition to scroll. See references/tiling-sprite.md.
  • "I want thousands of identical sprites" → Use ParticleContainer with Particle instances (see pixijs-scene-particle-container), not plain sprites.
  • "I want to draw shapes or paths" → Use Graphics (see pixijs-scene-graphics), not a sprite.

Quick concepts

Anchor vs pivot

Sprite.anchor is normalized [0, 1] and shifts only the texture draw origin; no position offset. Container.pivot is pixel-space and shifts both the transform origin and the visual position. For centering a sprite, always use anchor.set(0.5).

Loading before creating

Sprite.from(id) only reads the Assets cache; it does not fetch. Always await Assets.load(...) first, or pass the returned Texture directly to new Sprite(texture).

Dynamic textures

Once a texture is loaded, modifying its frame or swapping its source does not automatically notify sprites. Set texture.dynamic = true once, or call sprite['onViewUpdate']() manually after changes.

Common Mistakes

[HIGH] Using Texture.from(url) to load

Wrong:

ts
const texture = Texture.from("https://example.com/image.png");

Correct:

ts
const texture = await Assets.load("https://example.com/image.png");

Texture.from() only reads the cache in v8. Use Assets.load() first; its return value is the texture.

[HIGH] Confusing anchor and pivot

Wrong:

ts
sprite.pivot.set(sprite.width / 2, sprite.height / 2);

Correct:

ts
sprite.anchor.set(0.5);

anchor shifts only the draw origin. pivot shifts the transform origin AND the visual position, causing the sprite to move unexpectedly.

[HIGH] Old NineSlicePlane name

NineSlicePlane was renamed to NineSliceSprite in v8 and switched to an options-object constructor: new NineSliceSprite({ texture, leftWidth, topHeight, rightWidth, bottomHeight }).

[MEDIUM] Adding children to a sprite

Sprite, NineSliceSprite, and TilingSprite all set allowChildren = false. Wrap in a Container to group sprites with other content.

API Reference

来源与署名

来源:pixijs/pixijs-skills位于skills/pixijs-scene-sprite提交83760c6

许可证: MIT

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架