Last active
May 16, 2023 06:19
-
-
Save vkbsb/330e31a54ab0256f7d9559d915dd13cd to your computer and use it in GitHub Desktop.
SlowMo in CC 3.7.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { _decorator, Component, game } from 'cc'; | |
const { ccclass, property } = _decorator; | |
function timeScalerDT(useFixedDeltaTime){ | |
this._useFixedDeltaTime = useFixedDeltaTime; | |
if (useFixedDeltaTime) { | |
this._startTime = performance.now(); | |
return this.frameTime / 1000; | |
} | |
const now = performance.now(); | |
this._deltaTime = now > this._startTime ? (now - this._startTime) / 1000 : 0; | |
if (this._deltaTime > Game.DEBUG_DT_THRESHOLD) { | |
this._deltaTime = this.frameTime / 1000; | |
} | |
this._startTime = now; | |
return this._deltaTime * (this.timeScale || 1); | |
} | |
@ccclass('GameHandler') | |
export class GameHandler extends TriggerObserver { | |
start() { | |
//initialization of the timeScalled DT. | |
game.timeScale = 1 | |
game._calculateDT = timeScalerDT | |
//example usage. | |
tween(this.node).call(()=>{ game.timeScale = 0.1 }).delay(0.25).call(()=>{ game.timeScale = 1 }).start() | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment