"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();