feat: update game timescale can effect to physics fixed time

feature/ads-smart-display
tiendat3699 2024-06-13 10:39:54 +07:00
parent f890a29fb1
commit c3c155cad5
2 changed files with 14 additions and 10 deletions

View File

@ -336,7 +336,7 @@
"_lpos": {
"__type__": "cc.Vec3",
"x": 540,
"y": 1169.9999999999995,
"y": 1169.9999999999998,
"z": 0
},
"_lrot": {
@ -387,7 +387,7 @@
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 2.2737367544323206e-13,
"y": 0,
"z": 1000
},
"_lrot": {
@ -427,7 +427,7 @@
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 1169.9999999999998,
"_orthoHeight": 1170,
"_near": 0,
"_far": 2000,
"_color": {
@ -17989,8 +17989,8 @@
"defaultAnimation": "stage5",
"_premultipliedAlpha": true,
"_timeScale": 1,
"_preCacheMode": 0,
"_cacheMode": 0,
"_preCacheMode": 1,
"_cacheMode": 1,
"_sockets": [],
"_useTint": false,
"_debugMesh": false,
@ -29721,9 +29721,9 @@
"__uuid__": "cc731501-912a-465f-9070-dbe0d8ad3598",
"__expectedType__": "cc.Prefab"
},
"weight": 10000,
"weight": 60,
"weightStepOnGoal": 0,
"maxWeight": 10000,
"maxWeight": 60,
"maxObjects": 1
},
{
@ -34995,7 +34995,7 @@
"_contentSize": {
"__type__": "cc.Size",
"width": 1080,
"height": 2339.9999999999995
"height": 2340
},
"_anchorPoint": {
"__type__": "cc.Vec2",

View File

@ -8,6 +8,7 @@ import {
Label,
Node,
NodeSpace,
PhysicsSystem2D,
Sprite,
Vec2,
Vec3,
@ -94,13 +95,16 @@ declare global {
//#region GAME
const fixedTime = PhysicsSystem2D.instance.fixedTimeStep;
Game.prototype.timeScale = 1;
// @ts-ignore
game._calculateDT = function (useFixedDeltaTime: number) {
game._calculateDT = function (useFixedDeltaTime: boolean) {
PhysicsSystem2D.instance.fixedTimeStep = fixedTime * game.timeScale;
this._useFixedDeltaTime = useFixedDeltaTime;
if (useFixedDeltaTime) {
this._startTime = performance.now();
return this.frameTime / 1000;
return (this.frameTime / 1000) * game.timeScale;
}
const now = performance.now();
this._deltaTime = now > this._startTime ? (now - this._startTime) / 1000 : 0;