<Application/>
Application 初始化引擎和渲染上下文,一个实例对应一个画布。
可配置填充、分辨率模式和图形设备选项。
import { Application } from '@playcanvas/react'
export default function Scene() {
return (
<Application
fillMode={FILLMODE_FILL_WINDOW}
resolutionMode={RESOLUTION_AUTO}
>
{/* Your scene content */}
</Application>
)
}
属性
| 名称 | 类型与说明 | 默认值 |
|---|---|---|
fillMode? | "NONE" | "FILL_WINDOW" | "KEEP_ASPECT"控制画布如何填满窗口,以及窗口变化时如何调整尺寸。 | FILLMODE_NONE |
resolutionMode? | "AUTO" | "FIXED"修改画布分辨率,并设置窗口调整尺寸时的行为。 | RESOLUTION_AUTO |
usePhysics? | boolean为 true 时启用 PlayCanvas 物理系统。 | false |
deviceTypes? | DeviceType[]图形设备类型的优先顺序。使用数组中第一个受浏览器支持的类型。 | [DEVICETYPE_WEBGL2] |
graphicsDeviceOptions? | GraphicsDeviceOptions图形设置。 | - |
children? | ReactNode应用的子元素。 | - |
renderNextFrame? | boolean设为 true 后,在主循环的下一次迭代渲染场景。仅在 autoRender 为 false 时有效,渲染完成后 renderNextFrame 自动恢复为 false。 | - |
timeScale? | number缩放全局时间增量,默认 1。脚本、动画和物理均接收缩放后的增量,因此 0 会同时停止它们。仅暂停或减慢物理而保持其他部分运行时,使用 RigidBodyComponentSystem#timeScale。 | - |
maxDeltaTime? | number限制每帧时间增量的上限,默认 0.1 秒。从后台标签页返回时 dt 可能很大,此设置可避免游戏状态异常。 | - |
scriptsOrder? | string[]优先加载的脚本及其顺序。 | - |
autoRender? | boolean为 true 时每帧调用应用的渲染函数,默认为 true。画面经常保持不变时,设为 false 可大幅降低 CPU 与 GPU 负载。 | - |
graphicsDevice? | GraphicsDevice应用使用的图形设备。 | - |
root? | Entity应用的根实体。 | - |
lightmapper? | Lightmapper | null运行时光照贴图生成器。 | - |
loader? | ResourceLoader资源加载器。 | - |
scenes? | SceneRegistry应用管理的场景注册表。 | - |
systems? | ComponentSystemRegistry应用的组件系统注册表。 | - |
i18n? | I18n处理本地化。 | - |
elementInput? | ElementInput | null处理 ElementComponent 的输入。 | - |
xr? | XrManager | null提供启动 VR/AR 会话能力的 XR 管理器。 | - |
defaultLayerWorld? | - | |
defaultLayerDepth? | - | |
defaultLayerSkybox? | - | |
defaultLayerUi? | - | |
defaultLayerImmediate? | - | |
context? | any | - |
className? | string添加到画布组件的 CSS 类名。 | pc-app |
style? | Record<string, unknown>添加到画布组件的样式对象。 | { width: '100%', height: '100%' } |