pixijs-create
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesecreate pixi.jsnpmyarnpnpmbun--templatecdcreate pixi.jsnpmyarnpnpmbun--templateQuick Start
快速开始
Scaffold a new project with interactive prompts:
bash
npm create pixi.js@latestOr skip prompts by passing a project name and template:
bash
npm create pixi.js@latest my-game -- --template bundler-viteThen:
bash
cd my-game
npm install
npm run devRequires Node.js 18+ or 20+. Some templates (notably and ) may require a newer Node version; the package manager will warn if so.
creation-webframework-react通过交互式提示搭建新项目:
bash
npm create pixi.js@latest或者通过指定项目名称和模板跳过提示:
bash
npm create pixi.js@latest my-game -- --template bundler-vite之后执行:
bash
cd my-game
npm install
npm run dev需要Node.js 18+或20+版本。部分模板(尤其是和)可能需要更新的Node版本;如果不符合要求,包管理器会发出警告。
creation-webframework-reactAdding PixiJS to an existing project
为现有项目添加PixiJS
If you already have a bundler, framework, or project set up, skip the CLI and install the package directly:
bash
npm install pixi.jsThen import from and construct an as shown in . The CLI templates are a convenience for new projects; they don't add anything to the library that can't give you.
pixi.jsApplicationpixijs-applicationnpm install pixi.jsRelated skills: (how the scaffolded + entry point works), (renderers and the render loop), (scene graph fundamentals for the first things you'll add to the stage), (loading textures, fonts, and bundles the template expects you to drop into or ).
pixijs-applicationnew Application()app.init()pixijs-core-conceptspixijs-scene-core-conceptspixijs-assetspublic/src/assets/如果你已经配置好打包器、框架或项目,可以跳过CLI直接安装包:
bash
npm install pixi.js然后从导入并构造,具体可参考。CLI模板只是为新项目提供便利,并不会提供无法获取的库内容。
pixi.jsApplicationpixijs-applicationnpm install pixi.js相关技能: (搭建好的 + 入口点的工作原理)、(渲染器与渲染循环)、(场景图基础,是你将添加到舞台的核心内容)、(加载模板预期你放入或的纹理、字体和资源包)。
pixijs-applicationnew Application()app.init()pixijs-core-conceptspixijs-scene-core-conceptspixijs-assetspublic/src/assets/Core Patterns
核心模式
Choose a package manager
选择包管理器
The command is the same shape for every package manager:
bash
npm create pixi.js@latest
yarn create pixi.js
pnpm create pixi.js
bun create pixi.jsUnder npm 7+ you must pass a before CLI flags so npm doesn't consume them:
--bash
npm create pixi.js@latest my-game -- --template bundler-viteYarn, pnpm, and bun don't need the extra separator:
bash
yarn create pixi.js my-game --template bundler-vite
pnpm create pixi.js my-game --template bundler-vite
bun create pixi.js my-game --template bundler-viteUse as the project name to scaffold into the current directory.
.所有包管理器的命令格式一致:
bash
npm create pixi.js@latest
yarn create pixi.js
pnpm create pixi.js
bun create pixi.js在npm 7+版本中,你必须在CLI标志前添加,避免npm解析这些标志:
--bash
npm create pixi.js@latest my-game -- --template bundler-viteYarn、pnpm和bun不需要额外的分隔符:
bash
yarn create pixi.js my-game --template bundler-vite
pnpm create pixi.js my-game --template bundler-vite
bun create pixi.js my-game --template bundler-vite使用作为项目名称,可将项目搭建到当前目录。
.Interactive flow
交互式流程
Running with no arguments walks through prompts:
- Project name (defaults to ).
pixi-project - Framework / template category.
- Variant (TypeScript vs JavaScript where applicable).
- Whether to install dependencies immediately (some runners).
At the end, the CLI prints the + install + dev commands for the manager you invoked it with.
cd不带参数运行命令会进入提示流程:
- 项目名称(默认值为)。
pixi-project - 框架/模板分类。
- 变体(适用时可选TypeScript或JavaScript)。
- 是否立即安装依赖(部分运行器支持)。
最后,CLI会输出你所使用的包管理器对应的 + 安装 + 开发命令。
cdNon-interactive flow
非交互式流程
Pass a project name and to skip all prompts. This is the form you want for scripts, CI, and quickstart docs:
--templatebash
npm create pixi.js@latest my-game -- --template bundler-vite指定项目名称和参数可跳过所有提示。这种形式适用于脚本、CI和快速入门文档:
--templatebash
npm create pixi.js@latest my-game -- --template bundler-viteAvailable template presets
可用的模板预设
Templates fall into two categories:
- Bundler templates (): generic PixiJS setup wired up with your bundler of choice. Use one of these when you want to pick your own structure.
bundler-* - Creation templates (): platform-tailored starters with extras already wired in (AssetPack, sound, UI, scene routing). Use one of these when you want batteries included.
creation-* - Framework templates (): PixiJS embedded inside a host framework like React.
framework-* - Extension templates (): scaffolding for building a reusable PixiJS package.
extension-*
For most new projects, is the recommended starting point.
bundler-vite| Template | What you get |
|---|---|
| Vite + TypeScript PixiJS project. The default first-stop template. |
| Vite + plain JavaScript. |
| Webpack + TypeScript. |
| Webpack + plain JavaScript. |
| esbuild + TypeScript. |
| esbuild + plain JavaScript. |
| No-bundler setup using a browser import map (good for learning / demos). |
| PixiJS Creation Engine web template with scene-based game scaffolding, AssetPack, sound, and UI integration. |
| React + TypeScript + PixiJS via the |
| React + plain JavaScript + PixiJS. |
| Starter for building a reusable PixiJS extension/package. |
The live list is maintained in the repo; run without arguments to see the current menu if you need to confirm.
create-pixinpm create pixi.js@latest模板分为两类:
- 打包器模板():通用PixiJS配置,适配你选择的打包器。当你想要自定义项目结构时可使用此类模板。
bundler-* - 创建模板():针对特定平台的启动模板,已集成额外功能(AssetPack、音效、UI、场景路由)。当你想要开箱即用的完整功能时可使用此类模板。
creation-* - 框架模板():将PixiJS嵌入到React等宿主框架中的模板。
framework-* - 扩展模板():用于构建可复用PixiJS包的脚手架模板。
extension-*
对于大多数新项目,推荐从开始。
bundler-vite| 模板名称 | 包含内容 |
|---|---|
| Vite + TypeScript PixiJS项目。默认的首选模板。 |
| Vite + 纯JavaScript。 |
| Webpack + TypeScript。 |
| Webpack + 纯JavaScript。 |
| esbuild + TypeScript。 |
| esbuild + 纯JavaScript。 |
| 无需打包器的设置,使用浏览器导入映射(适合学习/演示)。 |
| PixiJS Creation Engine网页模板,包含基于场景的游戏脚手架、AssetPack、音效和UI集成。 |
| React + TypeScript + 通过 |
| React + 纯JavaScript + PixiJS。 |
| 用于构建可复用PixiJS扩展/包的启动模板。 |
最新的模板列表维护在仓库中;如需确认,可不带参数运行查看当前菜单。
create-pixinpm create pixi.js@latestPost-scaffold flow
项目搭建后的流程
Every template ships with the same three-step onboarding:
bash
cd my-game
npm install
npm run devnpm run devsrc/Other scripts every template exposes (names may vary slightly by preset):
- : produce a production build in
npm run build.dist/ - /
npm run preview: serve the production build locally.npm run serve - : run the template's configured linter if it ships one.
npm run lint
每个模板都包含相同的三步入门流程:
bash
cd my-game
npm install
npm run devnpm run devsrc/每个模板还提供其他脚本(名称可能因预设略有不同):
- :在
npm run build目录生成生产构建产物。dist/ - /
npm run preview:在本地预览生产构建产物。npm run serve - :运行模板配置的代码检查工具(如果模板包含的话)。
npm run lint
Scaffolding into an existing directory
搭建到现有目录
Use as the project name to write into the current working directory. The CLI refuses to run if non-empty and conflicting files exist unless you confirm the prompt.
.bash
mkdir my-game
cd my-game
npm create pixi.js@latest . -- --template bundler-vite使用作为项目名称,可将项目写入当前工作目录。如果目录非空且存在冲突文件,CLI会拒绝运行,除非你确认提示。
.bash
mkdir my-game
cd my-game
npm create pixi.js@latest . -- --template bundler-viteNext steps
后续步骤
After starts, the template opens on a blank or bunny-sprite scene. The usual progression is:
npm run dev- Read to understand how the template's entry point constructs
pixijs-applicationand callsnew Application(), howawait app.init(...)/app.stage/app.rendererhang together, and how the ResizePlugin and TickerPlugin behave by default.app.canvas - Read for the renderer and render-loop mental model.
pixijs-core-concepts - Read before adding your first non-trivial scene so you know the container-vs-leaf rule upfront.
pixijs-scene-core-concepts - Drop in textures via once you're ready to load real art.
pixijs-assets
npm run dev- 阅读,了解模板入口点如何构造
pixijs-application并调用new Application(),await app.init(...)/app.stage/app.renderer如何协同工作,以及ResizePlugin和TickerPlugin的默认行为。app.canvas - 阅读,建立渲染器和渲染循环的思维模型。
pixijs-core-concepts - 在添加第一个复杂场景前,阅读,提前了解容器与叶子节点的规则。
pixijs-scene-core-concepts - 准备好加载实际资源后,通过添加纹理。
pixijs-assets
Common Mistakes
常见错误
[HIGH] Missing --
separator on npm 7+
--[高风险] npm 7+版本中缺少--
分隔符
--Wrong:
bash
npm create pixi.js@latest my-game --template bundler-viteCorrect:
bash
npm create pixi.js@latest my-game -- --template bundler-vitenpm 7+ consumes flags after the package spec unless you pass to forward them. Without the separator, the CLI ignores and drops back to the interactive prompt. Yarn, pnpm, and bun don't need the separator.
----template错误写法:
bash
npm create pixi.js@latest my-game --template bundler-vite正确写法:
bash
npm create pixi.js@latest my-game -- --template bundler-vitenpm 7+会解析包规范后的标志,除非你添加来传递这些标志。如果没有分隔符,CLI会忽略参数并回到交互式提示。Yarn、pnpm和bun不需要该分隔符。
----template[MEDIUM] Running with an old Node version
[中风险] 使用旧版本Node.js
PixiJS requires Node 18+ or 20+. Some templates (framework-react, creation-web) expect a newer Node for their tooling. Upgrade Node before re-running the CLI if you see an "engines" warning from your package manager.
PixiJS需要Node 18+或20+版本。部分模板(framework-react、creation-web)的工具链需要更新的Node版本。如果包管理器发出“engines”警告,请先升级Node版本再重新运行CLI。
[MEDIUM] Top-level await app.init()
broken in Vite production builds
await app.init()[中风险] Vite生产构建中顶级await app.init()
失效
await app.init()On Vite versions , top-level works in dev but breaks in production builds, so a project that does this at module scope will fail after :
<=6.0.6awaitbundler-vitenpm run buildts
const app = new Application();
await app.init({ resizeTo: window }); // broken at module top level in prodWrap the init in an async IIFE instead:
ts
(async () => {
const app = new Application();
await app.init({ resizeTo: window });
document.body.appendChild(app.canvas);
})();Upgrading Vite past 6.0.6 also resolves it, but the IIFE pattern is safe on every version and matches the PixiJS quick-start guide.
在Vite版本中,顶级在开发环境正常工作,但在生产构建中会失效,因此项目中如果在模块作用域执行以下代码,后会失败:
<=6.0.6awaitbundler-vitenpm run buildts
const app = new Application();
await app.init({ resizeTo: window }); // 生产环境中模块顶级的此代码会失效改为将初始化代码包裹在异步立即执行函数表达式(IIFE)中:
ts
(async () => {
const app = new Application();
await app.init({ resizeTo: window });
document.body.appendChild(app.canvas);
})();将Vite升级到6.0.6以上版本也可解决此问题,但IIFE模式在所有版本中都安全,且与PixiJS快速入门指南一致。
API Reference
API参考
- create-pixi on GitHub
- create-pixi documentation site
- Application: the class the generated entry point instantiates.
- GitHub上的create-pixi
- create-pixi文档站点
- Application:生成的入口点实例化的类。