mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 19:12:40 +08:00
adjust physics system interface (#4759)
This commit is contained in:
committed by
Weiliang Wang
parent
9b3858a3e7
commit
3d2c385b7a
@@ -11,9 +11,11 @@ import { createPhysicsWorld } from '../../physics/instance';
|
||||
*/
|
||||
export class PhysicsSystem {
|
||||
private _world: PhysicsWorldBase;
|
||||
private _paused = false;
|
||||
private _singleStep = false;
|
||||
private _enable = true;
|
||||
private _deltaTime = 1.0 / 60.0;
|
||||
private _maxSubStep = 2;
|
||||
// private _frameRate = 60;
|
||||
// private _singleStep = false;
|
||||
|
||||
constructor () {
|
||||
this._world = createPhysicsWorld();
|
||||
@@ -21,40 +23,79 @@ export class PhysicsSystem {
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 设置是否只运行一步。
|
||||
* @param b - 布尔值
|
||||
* 获取或设置是否启用物理系统,可以用于暂停或继续运行物理系统。
|
||||
*/
|
||||
public setSingleStep (b: boolean) {
|
||||
this._singleStep = b;
|
||||
public get enable (): boolean {
|
||||
return this._enable;
|
||||
}
|
||||
|
||||
public set enable (value: boolean) {
|
||||
this._enable = value;
|
||||
}
|
||||
|
||||
// shielding for alpha version
|
||||
// /**
|
||||
// * @zh
|
||||
// * 获取或设置是否只运行一步。
|
||||
// * @param {boolean} b
|
||||
// */
|
||||
// public get singleStep () {
|
||||
// return this._singleStep;
|
||||
// }
|
||||
|
||||
// public set singleStep (b: boolean) {
|
||||
// this._singleStep = b;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 获取或设置每帧模拟的最大子步数。
|
||||
*/
|
||||
public get maxSubStep () {
|
||||
return this._maxSubStep;
|
||||
}
|
||||
|
||||
public set maxSubStep (value: number) {
|
||||
this._maxSubStep = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 继续。
|
||||
* 获取或设置每步模拟消耗的固定时间。
|
||||
*/
|
||||
public resume () {
|
||||
this._paused = false;
|
||||
public get deltaTime () {
|
||||
return this._deltaTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 暂停。
|
||||
*/
|
||||
public pause () {
|
||||
this._paused = true;
|
||||
public set deltaTime (value: number) {
|
||||
this._deltaTime = value;
|
||||
}
|
||||
|
||||
// shielding for alpha version
|
||||
// /**
|
||||
// * @zh
|
||||
// * 获取或设置物理每秒模拟的帧率。
|
||||
// */
|
||||
// public get frameRate () {
|
||||
// return this._frameRate;
|
||||
// }
|
||||
|
||||
// public set frameRate (value: number) {
|
||||
// this._frameRate = value;
|
||||
// this._deltaTime = 1 / this._frameRate;
|
||||
// }
|
||||
|
||||
public update (deltaTime: number) {
|
||||
if (CC_EDITOR) {
|
||||
return;
|
||||
}
|
||||
if (this._paused) {
|
||||
if (!this._enable) {
|
||||
return;
|
||||
}
|
||||
this._world.step(this._deltaTime);
|
||||
if (this._singleStep) {
|
||||
this._paused = true;
|
||||
}
|
||||
this._world.step(this._deltaTime, deltaTime, this._maxSubStep);
|
||||
// if (this._singleStep) {
|
||||
// this._enable = false;
|
||||
// }
|
||||
}
|
||||
|
||||
get world () {
|
||||
|
||||
Reference in New Issue
Block a user