game-setup-and-config
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGame Setup and Config
游戏设置与配置
How to create a Phaser.Game instance with the right GameConfig options for renderer, scaling, pixel art, FPS, and canvas placement.
Key source paths: , , , ,
Related skills: ../scenes/SKILL.md, ../loading-assets/SKILL.md, ../scale-and-responsive/SKILL.md
src/core/Game.jssrc/core/Config.jssrc/core/typedefs/GameConfig.jssrc/const.jssrc/scale/const/如何创建带有合适GameConfig选项的Phaser.Game实例,涵盖渲染器、缩放、像素艺术、FPS和画布布局相关配置。
核心源码路径: , , , ,
相关技能: ../scenes/SKILL.md, ../loading-assets/SKILL.md, ../scale-and-responsive/SKILL.md
src/core/Game.jssrc/core/Config.jssrc/core/typedefs/GameConfig.jssrc/const.jssrc/scale/const/Quick Start
快速开始
The simplest possible Phaser 4 game -- a single scene with the default 1024×768 canvas:
js
class MyScene extends Phaser.Scene {
preload() {
this.load.image('logo', 'assets/logo.png');
}
create() {
this.add.image(400, 300, 'logo');
}
}
const config = {
type: Phaser.AUTO,
scene: MyScene
};
const game = new Phaser.Game(config);new Phaser.Game(config)ConfigTimeStepDOMContentLoaded最简单的Phaser 4游戏——一个带有默认1024×768画布的单一场景:
js
class MyScene extends Phaser.Scene {
preload() {
this.load.image('logo', 'assets/logo.png');
}
create() {
this.add.image(400, 300, 'logo');
}
}
const config = {
type: Phaser.AUTO,
scene: MyScene
};
const game = new Phaser.Game(config);new Phaser.Game(config)ConfigTimeStepDOMContentLoadedCore Concepts
核心概念
Boot Sequence (src/core/Game.js)
启动流程(src/core/Game.js)
- -- parses config into a
new Phaser.Game(config)instance.Phaser.Core.Config - Creates global managers: ,
AnimationManager,TextureManager,CacheManager,InputManager,SceneManager,ScaleManager,SoundManager,TimeStep.PluginManager - Waits for , then calls
DOMContentLoaded.boot() - creates the renderer (
boot()), adds the canvas to the DOM (CreateRenderer), prints the debug header, emitsAddToDOM.BOOT - Once textures are ready (emits
TextureManager), emitsREADYthen callsREADY.start() - begins the
start()loop, sets up theTimeStep, callsVisibilityHandler.config.postBoot
- ——将配置解析为
new Phaser.Game(config)实例。Phaser.Core.Config - 创建全局管理器:、
AnimationManager、TextureManager、CacheManager、InputManager、SceneManager、ScaleManager、SoundManager、TimeStep。PluginManager - 等待事件,然后调用
DOMContentLoaded方法。boot() - 创建渲染器(
boot()),将画布添加到DOM中(CreateRenderer),打印调试头部信息,触发AddToDOM事件。BOOT - 当纹理准备就绪后(触发
TextureManager事件),触发READY事件,然后调用READY方法。start() - 启动
start()循环,设置TimeStep,调用VisibilityHandler。config.postBoot
Config Parsing (src/core/Config.js)
配置解析(src/core/Config.js)
The constructor reads a flat object and resolves defaults. Some properties can be specified at top level OR nested inside sub-objects (e.g., can be top-level or under ). The sub-object takes priority when both are present.
ConfigGameConfigwidthscale.widthscaleRender properties can likewise be top-level shortcuts (e.g., ) or nested under .
pixelArt: truerenderConfigGameConfigwidthscale.widthscale渲染相关属性同样可以使用顶层快捷方式(例如)或嵌套在子对象中。
pixelArt: truerenderRenderer Constants (src/const.js)
渲染器常量(src/const.js)
| Constant | Value | Behavior |
|---|---|---|
| | WebGL if supported, else falls back to Canvas |
| | Force Canvas renderer |
| | Force WebGL -- no fallback if unsupported |
| | No renderer -- DOM still required. For unit testing only |
Set via . Default is .
config.typePhaser.AUTO| 常量 | 值 | 行为 |
|---|---|---|
| | 支持WebGL则使用WebGL,否则回退到Canvas |
| | 强制使用Canvas渲染器 |
| | 强制使用WebGL——不支持时无回退方案 |
| | 无渲染器——仍需要DOM。仅用于单元测试 |
通过设置,默认值为。
config.typePhaser.AUTOCommon Patterns
常见配置模式
Pixel Art Game
像素艺术游戏
When is , Config automatically sets , , and .
pixelArttrueantialias: falseantialiasGL: falseroundPixels: truejs
const config = {
type: Phaser.AUTO,
width: 320,
height: 240,
pixelArt: true,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
zoom: Phaser.Scale.ZOOM_2X
},
scene: MyScene
};当设为时,Config会自动设置、和。
pixelArttrueantialias: falseantialiasGL: falseroundPixels: truejs
const config = {
type: Phaser.AUTO,
width: 320,
height: 240,
pixelArt: true,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
zoom: Phaser.Scale.ZOOM_2X
},
scene: MyScene
};Smooth Pixel Art (WebGL only)
平滑像素艺术(仅WebGL)
Preserves blocky pixels but smooths edges between them when scaled up:
js
const config = {
type: Phaser.WEBGL,
width: 320,
height: 240,
smoothPixelArt: true,
scene: MyScene
};When is , Config sets , , and .
smoothPixelArttrueantialias: trueantialiasGL: truepixelArt: false放大时保留块状像素,但平滑像素之间的边缘:
js
const config = {
type: Phaser.WEBGL,
width: 320,
height: 240,
smoothPixelArt: true,
scene: MyScene
};当设为时,Config会设置、和。
smoothPixelArttrueantialias: trueantialiasGL: truepixelArt: falseFull-Window Responsive Game
全窗口响应式游戏
js
const config = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.RESIZE,
parent: 'game-container',
width: '100%',
height: '100%'
},
scene: MyScene
};js
const config = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.RESIZE,
parent: 'game-container',
width: '100%',
height: '100%'
},
scene: MyScene
};Fixed Aspect Ratio with FIT
固定宽高比且适配容器
js
const config = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.FIT,
parent: 'game-container',
autoCenter: Phaser.Scale.CENTER_BOTH,
width: 1280,
height: 720,
min: { width: 640, height: 360 },
max: { width: 1920, height: 1080 }
},
backgroundColor: '#2d2d2d',
scene: MyScene
};js
const config = {
type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.FIT,
parent: 'game-container',
autoCenter: Phaser.Scale.CENTER_BOTH,
width: 1280,
height: 720,
min: { width: 640, height: 360 },
max: { width: 1920, height: 1080 }
},
backgroundColor: '#2d2d2d',
scene: MyScene
};Custom FPS Limit
自定义FPS限制
js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
fps: {
target: 60,
limit: 30,
forceSetTimeOut: false,
smoothStep: true
},
scene: MyScene
};js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
fps: {
target: 60,
limit: 30,
forceSetTimeOut: false,
smoothStep: true
},
scene: MyScene
};Transparent Canvas Over HTML
透明画布覆盖HTML
js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
transparent: true,
parent: 'game-container',
scene: MyScene
};When is , is forced to with alpha .
transparenttruebackgroundColor0x0000000js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
transparent: true,
parent: 'game-container',
scene: MyScene
};当设为时,会被强制设为且透明度为。
transparenttruebackgroundColor0x0000000Pre-existing Canvas Element
使用已存在的画布元素
js
const canvas = document.getElementById('my-canvas');
const config = {
type: Phaser.WEBGL,
canvas: canvas,
width: 800,
height: 600,
scene: MyScene
};js
const canvas = document.getElementById('my-canvas');
const config = {
type: Phaser.WEBGL,
canvas: canvas,
width: 800,
height: 600,
scene: MyScene
};Multiple Scenes
多场景配置
js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: [BootScene, PreloadScene, MenuScene, GameScene],
physics: {
default: 'arcade',
arcade: { gravity: { y: 300 } }
}
};Only the first scene starts automatically. Others start only if they have in their scene config. See ../scenes/SKILL.md.
{ active: true }js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
scene: [BootScene, PreloadScene, MenuScene, GameScene],
physics: {
default: 'arcade',
arcade: { gravity: { y: 300 } }
}
};只有第一个场景会自动启动。其他场景只有在其配置中包含时才会启动。详见../scenes/SKILL.md。
{ active: true }Boot Callbacks
启动回调
js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
callbacks: {
preBoot: function (game) {
// Runs before Phaser boots. Game systems not yet available.
},
postBoot: function (game) {
// Runs after boot. All systems ready, game loop starting.
}
},
scene: MyScene
};js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
callbacks: {
preBoot: function (game) {
// 在Phaser启动前运行,此时游戏系统尚未可用。
},
postBoot: function (game) {
// 在启动后运行,所有系统已就绪,游戏循环即将开始。
}
},
scene: MyScene
};Disabling Input Subsystems
禁用输入子系统
js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
input: {
keyboard: true,
mouse: true,
touch: false,
gamepad: false,
activePointers: 1,
windowEvents: true
},
disableContextMenu: true,
scene: MyScene
};js
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
input: {
keyboard: true,
mouse: true,
touch: false,
gamepad: false,
activePointers: 1,
windowEvents: true
},
disableContextMenu: true,
scene: MyScene
};Configuration Reference
配置参考
Top-Level GameConfig Properties
顶层GameConfig属性
| Property | Type | Default | Description |
|---|---|---|---|
| | | Renderer: |
| | | Game width in pixels (or |
| | | Game height in pixels (or |
| | | Canvas zoom multiplier. Overridden by |
| | | DOM element or |
| | | Provide your own canvas element |
| | | Provide your own rendering context |
| | | CSS styles applied to the canvas element |
| | | Skip feature detection for non-browser environments. |
| | | Scene class (extends Phaser.Scene) or array of scene classes |
| | | Seed for |
| | | Game title shown in console banner |
| | | Game URL shown in console banner |
| | | Game version shown in console banner |
| | | Auto-focus window on boot and mousedown |
| | | |
| | | Disable right-click context menu |
| | | Canvas background color. Accepts hex number, CSS string, or color object |
| | (shown) | |
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | | 渲染器类型: |
| | | 游戏宽度(像素,或 |
| | | 游戏高度(像素,或 |
| | | 画布缩放倍数。会被 |
| | | 画布的DOM元素或 |
| | | 使用自定义画布元素 |
| | | 使用自定义渲染上下文 |
| | | 应用于画布元素的CSS样式 |
| | | 跳过非浏览器环境的特性检测。若设为 |
| | | 场景类(继承自Phaser.Scene)或场景类数组 |
| | | |
| | | 控制台横幅中显示的游戏标题 |
| | | 控制台横幅中显示的游戏URL |
| | | 控制台横幅中显示的游戏版本 |
| | | 启动和鼠标按下时自动聚焦窗口 |
| | | |
| | | 禁用右键上下文菜单 |
| | | 画布背景色。支持十六进制数、CSS字符串或颜色对象 |
| | 显示 | |
scale (Phaser.Types.Core.ScaleConfig)
scale(Phaser.Types.Core.ScaleConfig)
| Property | Type | Default | Description |
|---|---|---|---|
| | | Base game width |
| | | Base game height |
| | | Zoom multiplier. Use constants: |
| | | DOM parent for the canvas |
| | | Scale mode (see table below) |
| | | Allow adjusting parent CSS height to 100% |
| | | Round display/style sizes for performance |
| | | Canvas centering mode (see table below) |
| | | Milliseconds between browser size checks |
| | | Element for fullscreen mode |
| | | Minimum canvas dimensions |
| | | Maximum canvas dimensions (0 = no limit) |
| | | Snap canvas size to multiples |
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | | 基础游戏宽度 |
| | | 基础游戏高度 |
| | | 缩放倍数。可使用常量: |
| | | 画布的DOM父元素 |
| | | 缩放模式(见下表) |
| | | 允许将父元素CSS高度调整为100% |
| | | 对显示/样式尺寸取整以提升性能 |
| | | 画布居中模式(见下表) |
| | | 浏览器尺寸检查的时间间隔(毫秒) |
| | | 全屏模式的目标元素 |
| | | 画布最小尺寸 |
| | | 画布最大尺寸(0表示无限制) |
| | | 将画布尺寸对齐到指定倍数 |
Scale Modes (src/scale/const/SCALE_MODE_CONST.js)
缩放模式(src/scale/const/SCALE_MODE_CONST.js)
| Constant | Value | Behavior |
|---|---|---|
| | No scaling. Canvas stays at config size |
| | Height adjusts based on width |
| | Width adjusts based on height |
| | Fit inside parent keeping aspect ratio (letterboxing) |
| | Cover parent keeping aspect ratio (may overflow) |
| | Canvas resizes to fill parent, ignoring aspect ratio |
| | Like RESIZE for visible area + FIT for canvas scale |
| 常量 | 值 | 行为 |
|---|---|---|
| | 不缩放,画布保持配置尺寸 |
| | 高度根据宽度自动调整 |
| | 宽度根据高度自动调整 |
| | 在父容器内适配,保持宽高比(会出现黑边) |
| | 覆盖父容器,保持宽高比(可能超出容器) |
| | 画布调整为填充父容器,忽略宽高比 |
| | 可视区域采用RESIZE模式,画布缩放采用FIT模式 |
Center Modes (src/scale/const/CENTER_CONST.js)
居中模式(src/scale/const/CENTER_CONST.js)
| Constant | Value |
|---|---|
| |
| |
| |
| |
| 常量 | 值 |
|---|---|
| |
| |
| |
| |
Zoom Constants (src/scale/const/ZOOM_CONST.js)
缩放常量(src/scale/const/ZOOM_CONST.js)
| Constant | Value | Behavior |
|---|---|---|
| | No zoom |
| | 2x zoom |
| | 4x zoom |
| | Max integer zoom that fits in parent |
| 常量 | 值 | 行为 |
|---|---|---|
| | 无缩放 |
| | 2倍缩放 |
| | 4倍缩放 |
| | 适配父容器的最大整数缩放倍数 |
render (Phaser.Types.Core.RenderConfig)
render(Phaser.Types.Core.RenderConfig)
These can be set at the top level OR nested under . The sub-object takes priority.
renderrender| Property | Type | Default | Description |
|---|---|---|---|
| | | Linear interpolation for scaled/rotated textures |
| | | Antialias on WebGL context creation |
| | | Sets |
| | | WebGL only. Blocky pixels with smooth edges |
| | | Snap texture-based objects to integer positions |
| | | Transparent canvas background |
| | | Clear canvas each frame |
| | | Preserve WebGL buffers between frames |
| | | Pre-multiplied alpha in WebGL drawing buffer |
| | | Desynchronized rendering context |
| | | Abort WebGL if browser reports poor performance |
| | | |
| | | Max quads per WebGL batch |
| | | Max GPU textures. |
| | | Max lights visible per camera |
| | | Restrict to 1 texture per batch on iOS/Android |
| | | Self-shadowing on lit textured objects |
| | | Point-combining threshold for Graphics WebGL paths |
| | | Skip drawing objects whose shader is still compiling |
| | | Mipmap filter: |
| | | Custom render nodes for WebGL renderer |
这些属性可以设置在顶层或嵌套在子对象中。子对象的属性优先级更高。
renderrender| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | | 缩放/旋转纹理时使用线性插值 |
| | | 创建WebGL上下文时启用抗锯齿 |
| | | 自动设置 |
| | | 仅WebGL。块状像素但边缘平滑 |
| | | 将基于纹理的对象对齐到整数位置 |
| | | 画布背景透明 |
| | | 每帧渲染前清空画布 |
| | | 帧之间保留WebGL缓冲区 |
| | | WebGL绘图缓冲区使用预乘alpha |
| | | 使用非同步渲染上下文 |
| | | 若浏览器报告性能不佳则终止WebGL初始化 |
| | | 可选值: |
| | | 每个WebGL批次的最大四边形数量 |
| | | GPU最大纹理数量。 |
| | | 每个相机可见的最大灯光数量 |
| | | 在iOS/Android上限制每个批次使用1个纹理 |
| | | 带光照的纹理对象启用自阴影 |
| | | Graphics WebGL路径的点合并阈值 |
| | | 跳过着色器仍在编译的对象绘制 |
| | | 多级纹理过滤: |
| | | WebGL渲染器的自定义渲染节点 |
fps (Phaser.Types.Core.FPSConfig)
fps(Phaser.Types.Core.FPSConfig)
| Property | Type | Default | Description |
|---|---|---|---|
| | | Minimum acceptable FPS |
| | | Target FPS (informational, does not enforce) |
| | | Enforce max FPS. |
| | | Use |
| | | Frames to average for delta smoothing |
| | | Frames before trusting delta again after a panic |
| | | Apply delta smoothing |
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| | | 最低可接受FPS |
| | | 目标FPS(仅作参考,不强制) |
| | | 强制限制最大FPS。 |
| | | 使用 |
| | | 用于delta平滑的平均帧数 |
| | | 出现异常后恢复信任delta所需的帧数 |
| | | 启用delta平滑 |
Other Sub-Configs
其他子配置
| Sub-Config Key | Type | Source |
|---|---|---|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| 子配置键 | 类型 | 源码路径 |
|---|---|---|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
Game Lifecycle, Pause/Resume, and Destroy
游戏生命周期、暂停/恢复与销毁
Game Lifecycle Events
游戏生命周期事件
Listen on (or from a Scene) for visibility and focus changes:
game.eventsthis.game.eventsjs
game.events.on('blur', () => { /* tab lost focus */ });
game.events.on('focus', () => { /* tab regained focus */ });
game.events.on('hidden', () => { /* Page Visibility API: page hidden */ });
game.events.on('visible', () => { /* Page Visibility API: page visible */ });
game.events.on('pause', () => { /* game.pause() was called */ });
game.events.on('resume', () => { /* game.resume() was called */ });Use named constants: , , , , , .
Phaser.Core.Events.BLURFOCUSHIDDENVISIBLEPAUSERESUME监听(或场景内的)以获取可见性和焦点变化:
game.eventsthis.game.eventsjs
game.events.on('blur', () => { /* 标签页失去焦点 */ });
game.events.on('focus', () => { /* 标签页重新获得焦点 */ });
game.events.on('hidden', () => { /* 页面可见性API:页面隐藏 */ });
game.events.on('visible', () => { /* 页面可见性API:页面可见 */ });
game.events.on('pause', () => { /* 调用了game.pause() */ });
game.events.on('resume', () => { /* 调用了game.resume() */ });可使用命名常量:、、、、、。
Phaser.Core.Events.BLURFOCUSHIDDENVISIBLEPAUSERESUMEPause and Resume
暂停与恢复
js
// Pause the entire game loop (rendering and updates stop)
game.pause();
// Resume the game loop
game.resume();
// Check if the game is currently paused
if (game.isPaused) {
// game loop is not running
}js
// 暂停整个游戏循环(渲染和更新停止)
game.pause();
// 恢复游戏循环
game.resume();
// 检查游戏是否处于暂停状态
if (game.isPaused) {
// 游戏循环未运行
}Destroying the Game
销毁游戏
js
// Remove the canvas from the DOM and clean up
game.destroy(true);
// Full cleanup -- pass noReturn=true if you will NEVER create another Phaser instance
// This allows the framework to release additional internal references
game.destroy(true, true);destroy(removeCanvas, noReturn)Phaser.Core.Events.DESTROYjs
// 从DOM中移除画布并清理资源
game.destroy(true);
// 完全清理——若永远不会再创建Phaser实例则传入noReturn=true
// 这允许框架释放更多内部引用
game.destroy(true, true);destroy(removeCanvas, noReturn)Phaser.Core.Events.DESTROYGlobal Game Members
全局游戏成员
The instance exposes key managers as properties, accessible from any Scene via :
Gamethis.game| Property | Type | Description |
|---|---|---|
| | Parsed GameConfig (read-only after boot) |
| | Start, stop, switch, and manage all scenes |
| | Shared data store across all scenes |
| | Global animation definitions |
| | Stores loaded non-texture assets (JSON, XML, etc.) |
| | Stores all loaded textures and sprite sheets |
| | Global sound playback manager |
js
// Example: access the registry from any scene
this.game.registry.set('highScore', 9999);
// Example: access the scene manager
this.game.scene.start('MenuScene');Gamethis.game| 属性 | 类型 | 描述 |
|---|---|---|
| | 解析后的GameConfig(启动后只读) |
| | 启动、停止、切换和管理所有场景 |
| | 所有场景共享的数据存储 |
| | 全局动画定义 |
| | 存储已加载的非纹理资源(JSON、XML等) |
| | 存储所有已加载的纹理和精灵表 |
| | 全局声音播放管理器 |
js
// 示例:在任意场景中访问registry
this.game.registry.set('highScore', 9999);
// 示例:访问场景管理器
this.game.scene.start('MenuScene');Gotchas and Common Mistakes
注意事项与常见错误
-
scale vs top-level config.,
width,height, andzoomcan be set at the top level or insideparent. Thescalesub-object values take priority. Avoid setting both to prevent confusion.scale -
Phaser.WEBGL has no fallback. Unlike, using
AUTOdirectly will not fall back to Canvas if WebGL is unavailable. The game will fail silently.Phaser.WEBGL -
parent: null vs parent: undefined.(or omitted) appends the canvas to
undefined.document.bodymeans Phaser will not add the canvas to the DOM at all -- you must do it yourself.null -
transparent overrides backgroundColor. When, the background color is forced to
transparent: trueregardless of what you set.rgba(0,0,0,0) -
fps.target does not enforce frame rate. It is advisory only. Useto actually cap the frame rate. The browser's display refresh rate is always the upper bound.
fps.limit -
fps.limit only slows down, never speeds up. Settingon a 60Hz display still results in 60 FPS.
limit: 120 -
DOM Container requires a parent. Settingwithout providing a
dom.createContainer: trueelement will not work.parent -
smoothPixelArt is WebGL-only. It has no effect with the Canvas renderer.
-
window.FORCE_WEBGL and window.FORCE_CANVAS. Config.js checks for these globals at the end of parsing and will override thesetting. This is intended for development/testing.
type -
Game.destroy() is asynchronous. It flags the game for destruction on the next frame. Listen for theevent to react to completion. Pass
DESTROYonly if you will never create another Phaser instance on the same page.noReturn: true
-
scale与顶层配置的优先级:、
width、height和zoom可在顶层或parent中设置。scale子对象的优先级更高。避免同时设置两者以防止混淆。scale -
Phaser.WEBGL无回退方案:与不同,直接使用
AUTO时,若不支持WebGL不会回退到Canvas,游戏会静默失败。Phaser.WEBGL -
parent: null与parent: undefined的区别:(或省略)会将画布添加到
undefined。document.body表示Phaser不会将画布添加到DOM,需手动处理。null -
transparent会覆盖backgroundColor:当时,背景色会被强制设为
transparent: true,无论你设置什么值。rgba(0,0,0,0) -
fps.target不强制帧率:它仅作参考。使用来实际限制帧率。浏览器的显示刷新率始终是上限。
fps.limit -
fps.limit只能降低帧率,无法提高:在60Hz显示器上设置仍会得到60 FPS。
limit: 120 -
DOM容器需要父元素:设置但未提供
dom.createContainer: true元素将无法生效。parent -
smoothPixelArt仅支持WebGL:对Canvas渲染器无效果。
-
window.FORCE_WEBGL和window.FORCE_CANVAS:Config.js在解析末尾会检查这些全局变量,并覆盖设置。这仅用于开发/测试。
type -
Game.destroy()是异步的:它会标记游戏在下一帧销毁。监听事件以响应销毁完成。仅当永远不会在同一页面创建另一个Phaser实例时才传入
DESTROY。noReturn: true
v4 Changes from v3
v4与v3的差异
- Default dimensions changed: Width defaults to (was
1024), height to800(was768).600 - EXPAND scale mode added: (value
Phaser.Scale.EXPAND) is new -- combines RESIZE visible area behavior with FIT canvas scaling.6 - Loader maxRetries default: defaults to
loader.maxRetries(was2in early v3).0 - smoothPixelArt option: New WebGL-only rendering mode that smooths edges between blocky pixels.
- renderNodes config: New property for custom WebGL render node registration.
render.renderNodes - skipUnreadyShaders: New option for parallel shader compilation to prevent stutter.
- pathDetailThreshold: New config for Graphics WebGL path point combining.
- 默认尺寸变更:宽度默认值为(原v3为
1024),高度默认值为800(原v3为768)。600 - 新增EXPAND缩放模式:(值为
Phaser.Scale.EXPAND)——结合RESIZE可视区域行为与FIT画布缩放。6 - Loader默认重试次数:默认值为
loader.maxRetries(v3早期为2)。0 - 新增smoothPixelArt选项:仅WebGL的渲染模式,平滑块状像素之间的边缘。
- 新增renderNodes配置:属性用于注册自定义WebGL渲染节点。
render.renderNodes - 新增skipUnreadyShaders:用于并行着色器编译以防止卡顿的选项。
- 新增pathDetailThreshold:Graphics WebGL路径点合并的配置项。
Source File Map
源码文件映射
| Concept | File |
|---|---|
| Game class / boot sequence | |
| Config parsing / all defaults | |
| GameConfig typedef | |
| Renderer constants (AUTO, WEBGL, CANVAS, HEADLESS) | |
| FPSConfig typedef | |
| RenderConfig typedef | |
| ScaleConfig typedef | |
| Scale mode constants | |
| Center constants | |
| Zoom constants | |
| TimeStep (game loop) | |
| Renderer creation | |
| ScaleManager | |
| CallbacksConfig typedef | |
| DOMContainerConfig typedef | |
| InputConfig typedef | |
| LoaderConfig typedef | |
| All core typedefs | |
| 概念 | 文件 |
|---|---|
| Game类 / 启动流程 | |
| 配置解析 / 所有默认值 | |
| GameConfig类型定义 | |
| 渲染器常量(AUTO、WEBGL、CANVAS、HEADLESS) | |
| FPSConfig类型定义 | |
| RenderConfig类型定义 | |
| ScaleConfig类型定义 | |
| 缩放模式常量 | |
| 居中常量 | |
| 缩放常量 | |
| TimeStep(游戏循环) | |
| 渲染器创建 | |
| ScaleManager | |
| CallbacksConfig类型定义 | |
| DOMContainerConfig类型定义 | |
| InputConfig类型定义 | |
| LoaderConfig类型定义 | |
| 所有核心类型定义 | |
| ", |