Get monitor refresh rate as an integer?

0 favourites
  • 10 posts
From the Asset Store
An even more advanced version of Spritefont that allows you to make all sorts of new things.
  • Is it possible to get the refresh rate of the monitor?

    From what I've seen C2's tick rate seems to match the monitor refresh rate.

    I'm building a real-time scrolling FPS graph, and I would like the max value on the graph to be the monitor refresh rate.

    Often the refresh rate will be 60, but there are also 120, and 144 Hz monitors (among others), and it would be nice if the graph could automatically adjust its max, to match the monitor refresh rate, when started.

    I know I might be able to guess the refresh rate by tracking the average frame rate, but I'm hoping to avoid that kind of solution if possible.

  • Actually, C2 is capped at 60 FPS rendered, no matter what the power of the CPU is and what the refresh rate of the client's monitor is.

    Moreover I'm afraid you don't have a definite access to the information "Monitor refresh rate" from the browser/HTML5.

  • Actually, C2 is capped at 60 FPS rendered.

    I read somewhere that trying to change this had catastrophic consequences, but I really wish this wasn't the case, for simpler games or, say, an editor app like mine 30 or even 15fps would be perfect. And, of course, save resources of all sorts.

  • Thanks for the reply Kyatric,

    I was afraid that the monitor refresh rate might have been hidden beyond reach from within a browser.

    Hey Somebody, you might be able to get some optimization by placing large amounts of run every tick code inside a group that runs every other tick, or every forth tick, in effect making some of the more intensive code run at around 30 to 15 fps. It would probably depend on the code though.

    As for the frame cap, I may be wrong, but it looks to me like C2's frame draw rate and event sheet tick rate can both increase beyond 60 Hz, to match monitor refresh rates greater than 60 Hz. Though the monitor refresh rate must be set before the game is launched. I don't know if this is normal behavior, but it seems to work on my system pretty much the way I'd expect.

    I recently reworked the movement and animation math in one of my games to make it frame rate independent, specifically so it would run correctly at both 60 Hz (for my older monitor), and 144 Hz (for my newer monitor).

    Beyond 60, so far I've only tried 85, 120, and 144 Hz refresh rates, though I mainly work with C2 at 60 and 144. In each case, it seems that C2 is forced to run events and draw frames at a rate matching the monitor refresh rate.

    Again, I could be misinterpreting what I'm seeing, but just now as a simple test, with my monitor set to 144 Hz, I created a sprite, gave it the "Drag and drop" behavior and then dragged it around the layout in a preview.

    In the Node Webkit preview, I got a C2 frame update matching every draw update of the windows hardware mouse pointer. Albeit with a one frame delay, because it's the hardware pointer after all, but I appear to be getting 144 updates per second from C2 none the less. That is, the sprite steps exactly the same distance as the hardware pointer with every C2 frame draw. If the mouse pointer was updating at 144 Hz, and C2 was updating at 60 Hz, then the sprite would be getting updated less often, and would need to step over a larger distance to keep up with the mouse pointer.

    In the Chrome preview, I got pretty much the same thing. 144 Hz.

    In the Firefox preview, I got a choppy mess with very little matchup between C2 frame draws and hardware pointer updates. The frame rate repeatedly went well below 60 fps, but that's pretty much what I always get from Firefox. Maybe I have Firefox configured wrong, or maybe it just doesn't like HTML5, either way C2 seems fine on every other browser, so I don't think it's an issue with C2.

    Okay, I actually just went back and added an FPS read-out to that test, via "every second, set text to 1 / dt".

    Node Webkit and Chrome show an average of almost exactly 144, and Firefox is closer to 90 on average, but fluctuated wildly, going as low as 20 fps every few seconds.

    On the off chance my system specs are important, I have Win 7, a pretty good Nvidia card, and variable refresh monitor with a max of 144 Hz. I can provide more detail if needed. Though other than the monitor refresh rate, I'm not sure what might be especially important.

  • Hey, fisholith, interesting idea - I might look into that. Will need to see what the performance change is like, if any.

  • Actually, C2 is capped at 60 FPS rendered

    That's not true actually - C2 games run at the refresh rate of the display, at least in modern browsers. Also even if on some platform the game is being capped at 60 FPS, it's not C2 doing it, it's the browser engine - we've coded our engine to run at any refresh rate.

    You generally can't get hardware information in a browser. Browser developers are very cagey about giving out hardware details since it improves fingerprinting on the web which has privacy implications. I don't think you actually need to get the refresh rate for what you described though - if you measure the FPS and the system is fast enough, then the FPS will report the refresh rate. You can default your graph to 60, but if the FPS goes over then set a new maximum for the graph. You could even round it up to known common refresh rates like 75, 120 etc.

  • Thanks for the clarification ASHLEY. Good to know I had the wrong information.

  • Thanks for the replies everyone.

    And thanks for the suggestion ASHLEY. I'm going to try doing a kind of running average over time of the frame rate I think. When directly using 1/dt with no temporal averaging, I tend to get some sudden single-tick spikes where 1/dt = 1000+, which throws off the max frame rate a little. :)

    I think as long as the game isn't running stably at a strangely low fps, it should work for guessing the monitor refresh rate decently.

    Thanks again. :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • fisholith - the system 'fps' expression is based on the number of frames over 1 second, and is probably a much less noisy measurement.

  • Hello! I used Acer predator for gaming. This is the best gaming monitor. It's refresh rate is 144Hz which is good for gaming. It provides me amazing gaming experience. I bought this PC after viewing the reviews at gamingbuff.com

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)