Add: global factor controlling fps base interval

This commit is contained in:
DaZuo0122
2026-02-15 09:40:51 +08:00
parent e5417b6799
commit f20ed1fd9d
12 changed files with 289 additions and 52 deletions

View File

@@ -53,6 +53,9 @@ const HALO_SAT_MIN = 0.15;
const HALO_VAL_MIN = 0.04;
const RENDER_FIT_PADDING = 16;
const MIN_RENDER_SCALE = 0.01;
const ANIMATION_SLOWDOWN_FACTOR_MIN = 1;
const ANIMATION_SLOWDOWN_FACTOR_MAX = 20;
const ANIMATION_SLOWDOWN_FACTOR_DEFAULT = 3;
export class PixiPetRenderer {
private app: Application;
@@ -63,6 +66,7 @@ export class PixiPetRenderer {
private frameCursor = 0;
private frameElapsedMs = 0;
private baseTexture: BaseTexture;
private animationSlowdownFactor = ANIMATION_SLOWDOWN_FACTOR_DEFAULT;
private disposed = false;
private constructor(
@@ -431,13 +435,24 @@ export class PixiPetRenderer {
this.layoutSprite();
}
setAnimationSlowdownFactor(factor: number): void {
if (!Number.isFinite(factor)) {
return;
}
const rounded = Math.round(factor);
this.animationSlowdownFactor = Math.min(
Math.max(rounded, ANIMATION_SLOWDOWN_FACTOR_MIN),
ANIMATION_SLOWDOWN_FACTOR_MAX
);
}
private startTicker(): void {
this.app.ticker.add((ticker) => {
if (this.disposed) {
return;
}
this.layoutSprite();
const frameMs = 1000 / Math.max(this.currentClip.fps, 1);
const frameMs = (1000 / Math.max(this.currentClip.fps, 1)) * this.animationSlowdownFactor;
this.frameElapsedMs += ticker.deltaMS;
if (this.frameElapsedMs < frameMs) {
return;