I don't really wanna explain why I want to limit the FPS, I just would like to know how I can do it. I've tried looking at how to limit it with pixiJS and nothing was changing, so I'm assuming something in MZ scripts is controlling it.
MZ How to limit max FPS to 50-60 in RMMZ?
JS Plugin RequestsYou're looking for the maxFPS property of whatever ticker is running the app. I'm not sure if you can make a plugin for this but the super hacky brute-force way of doing it would be to edit the rmmz_core.js file and insert a line that uses that property. Something like:
You can read more about the Ticker and the maxFPS property here: https://pixijs.download/dev/docs/PIXI.Ticker.html/PIXI.Ticker.html#maxFPS
JavaScript:
// This code can be found around line 1014 in the rmmz_core.js file:
Graphics._createPixiApp = function() {
try {
this._setupPixi();
this._app = new PIXI.Application({
view: this._canvas,
autoStart: false
});
this._app.ticker.remove(this._app.render, this._app);
this._app.ticker.add(this._onTick, this);
// << Begining of our changes
const myMaxFPS = 30; // Change this number based on what you want the max FPS to be.
this._app.ticker.maxFPS = myMaxFPS;
// >> End of our changes
} catch (e) {
this._app = null;
}
};
You can read more about the Ticker and the maxFPS property here: https://pixijs.download/dev/docs/PIXI.Ticker.html/PIXI.Ticker.html#maxFPS
it worked thank you <3
now i'm just trying to find a way to get Graphics._createPixiApp to work in my own plugin
The ticker refreshed at 120 FPS but the actual game loop is actually refreshed at 60 FPS. This means that every 2 graphics frame refresh, the game is refreshed once. So, while the FPS is shown at 120 FPS, the game is not at 60 FPS.
During normal usage, the delta time is shown as 0.5 (you can try to print it out of console), which means, every 2 ticks, the game is updated once.
JavaScript:
// Execute on each tick
Graphics._onTick = function(deltaTime) {
this._fpsCounter.startTick();
if (this._tickHandler) {
this._tickHandler(deltaTime);
}
if (this._canRender()) {
this._app.render();
}
this._fpsCounter.endTick();
};
// Set tick handler here
SceneManager.initGraphics = function() {
if (!Graphics.initialize()) {
throw new Error("Failed to initialize graphics.");
}
Graphics.setTickHandler(this.update.bind(this));
};
// The tick handler function
SceneManager.update = function(deltaTime) {
try {
const n = this.determineRepeatNumber(deltaTime);
for (let i = 0; i < n; i++) {
this.updateMain();
}
} catch (e) {
this.catchException(e);
}
};
// Repeat number.
SceneManager.determineRepeatNumber = function(deltaTime) {
// [Note] We consider environments where the refresh rate is higher than
// 60Hz, but ignore sudden irregular deltaTime.
this._smoothDeltaTime *= 0.8;
this._smoothDeltaTime += Math.min(deltaTime, 2) * 0.2;
if (this._smoothDeltaTime >= 0.9) {
this._elapsedTime = 0;
return Math.round(this._smoothDeltaTime);
} else {
this._elapsedTime += deltaTime;
if (this._elapsedTime >= 1) {
this._elapsedTime -= 1;
return 1;
}
return 0;
}
};
I'm guessing this is a typo, but if it's not I'm confused what you mean by "while the FPS is shown at 120 FPS, the game is not at 60 FPS." I tried logging the deltatime and it was showing about 1 and 0.04 something for 60FPS and 1-2 for 30FPS. I'm still pretty confused at what any of this means.
Edit:
Okay i kind of understand what you mean, i think. While the game is displayed at 60FPS or any FPS, it's updated at a different time? I don't really understand this too well, but I'm guessing that's what makes it not reliant on FPS for speed like RMXP, VXAce, MV.
It's not a typo.
What I mean is that in the RGSS engine, your game speed is determined by the FPS. The higher FPS, the faster your game will be. Probably it is the same case as MV, but I can't be sure. I didn't look at MV closely.
While it is not the case in RMMZ. 120 FPS is the graphics refresh rate. The screen is refreshed 120 times per second. But the game is updated 60 times per second. So, if something happens that puts a burden that the FPS will drop from 120 FPS to say 70 FPS, the game will still run fine and you will not notice the difference because the game updates the loop at 60 times per second.
What I mean is that in the RGSS engine, your game speed is determined by the FPS. The higher FPS, the faster your game will be. Probably it is the same case as MV, but I can't be sure. I didn't look at MV closely.
While it is not the case in RMMZ. 120 FPS is the graphics refresh rate. The screen is refreshed 120 times per second. But the game is updated 60 times per second. So, if something happens that puts a burden that the FPS will drop from 120 FPS to say 70 FPS, the game will still run fine and you will not notice the difference because the game updates the loop at 60 times per second.
Ah alright, I tried out different FPS' and didn't notice much of a difference until I went to 40 FPS, the speed of my character suddenly went up??
this is seconds to cross the map from one end to the other
120FPS = 2.6 seconds
60FPS = 2.67 seconds
50FPS = 3.34 seconds
40FPS = 2.00 seconds
30FPS = 2.47 seconds
for some reason 40FPS just makes everything faster, with both the animation frequency and speed. both of these helped me fix it and understand it a little more, but I haven't figured out why 40FPS like suddenly boosts game speed, but I guess it doesn't matter. I'll lock my game to 60 or 30 FPS.
How did you manage to get the game to fix to 40fps?
@idioteque , please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.
Original thread: https://forums.rpgmakerweb.com/threads/how-to-limit-max-fps-to-50-60-in-rmmz.133226/