218875a0-27ef-47b7-a832-58e3c68cfd74.js
3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"use strict";
cc._RF.push(module, '21887WgJ+9Ht6gyWOPGjP10', 'PhysicsControl');
// scripts/kernel/physics/PhysicsControl.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PhysicsControl = void 0;
var PhysicsControl = /** @class */ (function () {
function PhysicsControl() {
}
Object.defineProperty(PhysicsControl, "ins", {
get: function () {
this._ins == null && (this._ins = new PhysicsControl());
return this._ins;
},
enumerable: false,
configurable: true
});
PhysicsControl.prototype.init = function () {
this._manager = cc.director.getPhysicsManager();
this._manager.enabled = true;
CC_DEV && (this._manager.debugDrawFlags = cc.PhysicsManager.DrawBits.e_aabbBit);
cc.PhysicsManager.prototype['updateClone'] = cc.PhysicsManager.prototype['update']; //缓存原来的update方法
cc.PhysicsManager.prototype['update'] = function (dt) {
return; //屏蔽原来的update方法
};
//添加自己的update接口
cc.PhysicsManager.prototype['updateNew'] = function (dt) {
var world = this._world;
if (!world || !this.enabled)
return;
this.emit('before-step');
this._steping = true;
var velocityIterations = cc.PhysicsManager.VELOCITY_ITERATIONS;
var positionIterations = cc.PhysicsManager.POSITION_ITERATIONS;
this._accumulator += dt;
var frameTime = PhysicsControl.UPDATE_FRAME_TIME;
if (this._accumulator >= frameTime) {
var count = Math.floor(this._accumulator / frameTime);
this._accumulator -= (count * frameTime);
var stepNum = count * PhysicsControl.TIME_SCALE;
for (var i_1 = 0; i_1 < stepNum; ++i_1) {
world.Step(frameTime, velocityIterations, positionIterations);
}
// world.Step(frameTime * count * PhysicsControl.TIME_SCALE, velocityIterations, positionIterations); //不补帧,延长物理步进的时间
}
if (this.debugDrawFlags) {
this._checkDebugDrawValid();
this._debugDrawer.clear();
world.DrawDebugData();
}
this._steping = false;
var events = this._delayEvents;
for (var i = 0, l = events.length; i < l; i++) {
var event = events[i];
event.target[event.func].apply(event.target, event.args);
}
events.length = 0;
this._syncNode();
};
};
/**设置物理刷新帧率 */
PhysicsControl.prototype.setFrameRate = function (value) {
PhysicsControl.UPDATE_FRAME_RATE = value;
PhysicsControl.UPDATE_FRAME_TIME = 1 / value;
};
/**设置物理世界时间缩放倍数 */
PhysicsControl.prototype.setTimeScale = function (value) {
PhysicsControl.TIME_SCALE = value;
};
PhysicsControl.prototype.setPhysicsEnable = function (value) {
this._manager.enabled = value;
};
PhysicsControl.prototype.getPhysicsEnable = function () {
return this._manager.enabled;
};
PhysicsControl.prototype.update = function (dt) {
this._manager['updateNew'](dt);
};
PhysicsControl.UPDATE_FRAME_RATE = 60;
PhysicsControl.UPDATE_FRAME_TIME = 1 / 60;
PhysicsControl.TIME_SCALE = 1;
PhysicsControl._ins = null;
return PhysicsControl;
}());
exports.PhysicsControl = PhysicsControl;
cc._RF.pop();