Skip to content

Instantly share code, notes, and snippets.

@vkbsb
Last active May 16, 2023 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkbsb/330e31a54ab0256f7d9559d915dd13cd to your computer and use it in GitHub Desktop.
Save vkbsb/330e31a54ab0256f7d9559d915dd13cd to your computer and use it in GitHub Desktop.
SlowMo in CC 3.7.x
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