@eva/plugin-matterjs
Advanced tools
@@ -9,9 +9,47 @@ import { Component } from '@eva/eva.js'; | ||
| /** | ||
| * 物理组件 | ||
| * | ||
| * Physics 组件为游戏对象提供 Matter.js 物理引擎支持。 | ||
| * 可以创建不同类型的刚体(矩形、圆形、多边形), | ||
| * 并自动同步物理引擎的位置和旋转到游戏对象的 Transform。 | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const ball = new GameObject('ball'); | ||
| * ball.addComponent(new Physics({ | ||
| * type: PhysicsType.CIRCLE, | ||
| * radius: 25, | ||
| * bodyOptions: { | ||
| * restitution: 0.8, // 弹性 | ||
| * density: 0.01 // 密度 | ||
| * } | ||
| * })); | ||
| * ``` | ||
| */ | ||
| export declare class Physics extends Component<PhysicsParams> { | ||
| /** 组件名称 */ | ||
| static componentName: string; | ||
| /** 物理体参数配置 */ | ||
| bodyParams: PhysicsParams; | ||
| /** Matter.js 物理体实例 */ | ||
| body: Matter.Body; | ||
| /** Matter.js 物理引擎实例 */ | ||
| private PhysicsEngine; | ||
| /** | ||
| * 初始化物理组件 | ||
| * @param params - 物理体参数 | ||
| */ | ||
| init(params: PhysicsParams): void; | ||
| /** | ||
| * 每帧更新物理状态 | ||
| * | ||
| * 将物理引擎计算的位置和旋转同步到游戏对象的 Transform 组件。 | ||
| */ | ||
| update(): void; | ||
| /** | ||
| * 组件销毁时调用 | ||
| * | ||
| * 从物理世界中移除物理体。 | ||
| */ | ||
| onDestroy(): void; | ||
@@ -37,13 +75,101 @@ } | ||
| /** | ||
| * 物理系统(基于 Matter.js) | ||
| * | ||
| * PhysicsSystem 集成了 Matter.js 2D 物理引擎,为游戏提供完整的刚体物理模拟。 | ||
| * 它管理物理世界、物理引擎的运行,并自动同步物理引擎的状态到游戏对象。 | ||
| * | ||
| * 主要功能: | ||
| * - 集成 Matter.js 物理引擎 | ||
| * - 管理物理世界和物理体 | ||
| * - 自动同步物理状态到游戏对象 | ||
| * - 支持鼠标交互约束 | ||
| * - 可配置物理引擎参数和渲染调试 | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * // 基础配置 | ||
| * game.addSystem(new PhysicsSystem({ | ||
| * resolution: 2, | ||
| * fps: 60, | ||
| * world: { | ||
| * gravity: { x: 0, y: 1 } // 重力方向 | ||
| * } | ||
| * })); | ||
| * | ||
| * // 开启调试渲染和鼠标交互 | ||
| * game.addSystem(new PhysicsSystem({ | ||
| * isTest: true, // 显示物理调试绘制 | ||
| * canvas: debugCanvas, | ||
| * mouse: { | ||
| * open: true // 启用鼠标拖拽物理体 | ||
| * }, | ||
| * world: { | ||
| * gravity: { x: 0, y: 1 } | ||
| * } | ||
| * })); | ||
| * ``` | ||
| */ | ||
| export declare class PhysicsSystem extends System<PhysicsSystemParams> { | ||
| /** 系统名称 */ | ||
| static systemName: string; | ||
| /** 物理引擎实例 */ | ||
| private engine; | ||
| /** | ||
| * 初始化物理系统 | ||
| * | ||
| * 配置物理引擎参数、创建物理世界、设置渲染分辨率等。 | ||
| * | ||
| * @param param - 物理系统配置参数 | ||
| * @param param.resolution - 渲染分辨率,默认 1 | ||
| * @param param.fps - 物理引擎更新帧率,默认 60 | ||
| * @param param.isTest - 是否开启调试渲染模式 | ||
| * @param param.element - 物理调试渲染的容器元素 | ||
| * @param param.canvas - 物理调试渲染的画布 | ||
| * @param param.deltaSampleSize - 时间步长采样大小 | ||
| * @param param.mouse - 鼠标交互配置 | ||
| * @param param.world - Matter.js 世界配置(重力、边界等) | ||
| */ | ||
| init(param?: PhysicsSystemParams): void; | ||
| /** | ||
| * System 被安装的时候,如果游戏还没有开始,那么会在游戏开始的时候调用。用于前置操作,初始化数据等。 | ||
| * | ||
| * Called while the System installed, if game is not begain, it will be called while begain. use to pre operation, init data. | ||
| */ | ||
| awake(): void; | ||
| /** | ||
| * System 被安装后,所有的 awake 执行完后 | ||
| * | ||
| * Called while the System installed, after all of systems' awake been called | ||
| */ | ||
| start(): void; | ||
| /** | ||
| * 每一次游戏循环调用,可以做一些游戏操作,控制改变一些组件属性。 | ||
| * | ||
| * Called by every loop, can do some operation, change some property or other component property. | ||
| */ | ||
| update(e: any): void; | ||
| componentChanged(changed: ComponentChanged): void; | ||
| /** | ||
| * 和 update?() 类似,在所有System和组件的 update?() 执行以后调用。 | ||
| * | ||
| * Like update, called all of gameobject update. | ||
| */ | ||
| lateUpdate(): void; | ||
| /** | ||
| * 游戏开始和游戏暂停后开始播放的时候调用。 | ||
| * | ||
| * Called while the game to play when game pause. | ||
| */ | ||
| onResume(): void; | ||
| /** | ||
| * 游戏暂停的时候调用。 | ||
| * | ||
| * Called while the game paused. | ||
| */ | ||
| onPause(): void; | ||
| /** | ||
| * System 被销毁的时候调用。 | ||
| * Called while the system be destroyed. | ||
| */ | ||
| onDestroy(): void; | ||
@@ -50,0 +176,0 @@ } |
+2
-2
| { | ||
| "name": "@eva/plugin-matterjs", | ||
| "version": "2.0.1-beta.27", | ||
| "version": "2.0.1-beta.28", | ||
| "description": "@eva/plugin-matterjs", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "@eva/eva.js": "2.0.1-beta.27", | ||
| "@eva/eva.js": "2.0.1-beta.28", | ||
| "@types/matter-js": "^0.17.5", | ||
@@ -24,0 +24,0 @@ "poly-decomp": "^0.3.0" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1226364
0.99%25847
1.47%3
50%+ Added
- Removed
Updated