mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
682c9d19dc
* physics system use fixed frame-rate * wakeup bodies before apply force and impulse
43 lines
883 B
TypeScript
43 lines
883 B
TypeScript
import { PhysicsWorldBase } from '../../physics/api';
|
|
import { createPhysicsWorld } from '../../physics/instance';
|
|
|
|
export class PhysicsSystem {
|
|
private _world: PhysicsWorldBase;
|
|
private _paused = false;
|
|
private _singleStep = false;
|
|
private _deltaTime = 1.0 / 60.0;
|
|
|
|
constructor () {
|
|
this._world = createPhysicsWorld();
|
|
}
|
|
|
|
public setSingleStep (b: boolean) {
|
|
this._singleStep = b;
|
|
}
|
|
|
|
public resume () {
|
|
this._paused = false;
|
|
}
|
|
|
|
public pause () {
|
|
this._paused = true;
|
|
}
|
|
|
|
public update (deltaTime: number) {
|
|
if (CC_EDITOR) {
|
|
return;
|
|
}
|
|
if (this._paused) {
|
|
return;
|
|
}
|
|
this._world.step(this._deltaTime);
|
|
if (this._singleStep) {
|
|
this._paused = true;
|
|
}
|
|
}
|
|
|
|
get world () {
|
|
return this._world;
|
|
}
|
|
}
|