MV - Using $gameSystem.playtimeText() for accurate playtime

● ARCHIVED · READ-ONLY
Started by RCDunn 5 posts View original ↗
  1. Hello,

    I have a menu plugin that refers to $gameSystem.playtimeText() and displays the game time for the player.

    However, the game engine calculates time played based on frames in rpg_objects.js:

    Code:
    Game_System.prototype.playtime = function() {
        return Math.floor(Graphics.frameCount / 60);
    };
    
    Game_System.prototype.playtimeText = function() {
        var hour = Math.floor(this.playtime() / 60 / 60);
        var min = Math.floor(this.playtime() / 60) % 60;
        var sec = this.playtime() % 60;
        return hour.padZero(2) + ':' + min.padZero(2) + ':' + sec.padZero(2);
    };

    I've found that if the player has a monitor with a higher refresh rate than 60 hz, the playtime clock runs faster than it should. One of my playtesters always had this issue, but I couldn't replicate it until I upgraded my monitor with a >60 hz rate and now my game time clock also runs fast. Note that this happens even with a monitor FPS sync plugin running such as Yanfly's YEP_FpsSynchOption.

    User Pix3M in an old thread suggested adjusting the actual formula such as:

    Code:
    Game_System.prototype.playtime = function() {
        return Math.floor(Graphics.frameCount / 30);
    };

    However, looking at this function I would guess that it's already checking the user's frame rate and returning it as a value? If that's the case, why would our game time run so fast?

    Thanks in advance.
  2. The frame count is updated once per SceneManager.update call, but that gets invoked via requestAnimationFrame, called once per browser frame.

    You could try saving this as a .js file (copy into a text editor, Save As > File Type: All Files, Filename: whatever.js) and importing as a plugin:
    JavaScript:
    (function(alias) {
      Graphics.render = function() {
        alias.apply(this, arguments);
        this.frameCount--;  // cancel frameCount++
      };
    })(Graphics.render);
    
    (function(alias) {
      SceneManager.updateScene = function() {
        alias.apply(this, arguments);
        Graphics.frameCount++;  // frame count now bound to scene updates
      };
    })(SceneManager.updateScene);
    I haven't tested because my monitor is 60 Hz, but let me know if it works~ :kaothx:
  3. caethyril said:
    The frame count is updated once per SceneManager.update call, but that gets invoked via requestAnimationFrame, called once per browser frame.

    You could try saving this as a .js file (copy into a text editor, Save As > File Type: All Files, Filename: whatever.js) and importing as a plugin:
    JavaScript:
    (function(alias) {
      Graphics.render = function() {
        alias.apply(this, arguments);
        this.frameCount--;  // cancel frameCount++
      };
    })(Graphics.render);
    
    (function(alias) {
      SceneManager.updateScene = function() {
        alias.apply(this, arguments);
        Graphics.frameCount++;  // frame count now bound to scene updates
      };
    })(SceneManager.updateScene);
    I haven't tested because my monitor is 60 Hz, but let me know if it works~ :kaothx:

    Yesss! Worked like a charm, thank you very much :)
  4. caethyril said:
    The frame count is updated once per SceneManager.update call, but that gets invoked via requestAnimationFrame, called once per browser frame.

    You could try saving this as a .js file (copy into a text editor, Save As > File Type: All Files, Filename: whatever.js) and importing as a plugin:
    JavaScript:
    (function(alias) {
      Graphics.render = function() {
        alias.apply(this, arguments);
        this.frameCount--;  // cancel frameCount++
      };
    })(Graphics.render);
    
    (function(alias) {
      SceneManager.updateScene = function() {
        alias.apply(this, arguments);
        Graphics.frameCount++;  // frame count now bound to scene updates
      };
    })(SceneManager.updateScene);
    I haven't tested because my monitor is 60 Hz, but let me know if it works~ :kaothx:
    OH MY GOSH YOU REALLY SAVED MY LIFE :"D, i;ve been searching for this soooo longg lot's of plugin doesn't work for me i even stopped searching to fix this issue, i can't believe your codes works like a charm just like that, i truly grateful and thankyou so much!
  5. Great, you're welcome!

    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.