Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How can I get the value of Current running Frame rate?

DJ

Some guy that did RMXP before
Member

I want to get the value of Current Frame Rate on RGSS1(RMXP), The FPS value that displayed when
I hit the F2 in Debug mode. Is there any way to get that value in script?
I'm thinking about displaying the FPS while not in Debug mode,
and calculate Average FPS for performance test.

I tried some methods such as modifying Graphics module and
Try to get the FPS by using Time class, But It seems It's not working.

Please, I'm counting on you guys.
 
iirc, there's a method named Graphics.frame_rate that returns exactly that... in case I'm horribly mistaken (which is anything but out of the question), try looking up a support topic I opened up myself a while back where I got helped.
 
[rgss]module Graphics
 
  class << self
   
    def toggle_display
      if @display == nil
        viewport = Viewport.new(0, 0, 60, 24)
        viewport.z = 100000
        @display = Sprite.new(viewport)
        @display.bitmap = Bitmap.new(60, 24)
        @display.bitmap.font.size = 16
        @display.bitmap.font.color = Color.new(0, 255, 00)
      elsif @display != nil
        @display = @display.dispose
      end
    end
   
    alias frame_rate_update update
    def update
      frame_rate_update
      if @display != nil
        @display.bitmap.clear
        @display.bitmap.fill_rect(0, 0, 60, 24, Color.new(0, 0, 0, 96))
        @display.bitmap.draw_text(0, 0, 60, 24, self.frame_rate.to_s, 1)
      end
    end
  end
end
 
Graphics.toggle_display
[/rgss]

Here would be a generic example. Toggle it with "Graphics.toggle_display"
 

DJ

Some guy that did RMXP before
Member

Sorry guys but you are missing the point. :-(
Graphics.frame_rate is static value, and It is set to 40 and will not change whatever my
game lags to 20~30 FPS or not.
fps.png

Look at this. The White text on Left is the value I got from Graphics.frame_rate. It is always 40.
And uppper one is the Actual FPS, displayed when F2 pressed on Debug Mode.
The Value I want is uppper one, not the 40.

ForeverZer0":2w32kghp said:
[rgss]module Graphics
 
  class << self
   
    def toggle_display
      if @display == nil
        viewport = Viewport.new(0, 0, 60, 24)
        viewport.z = 100000
        @display = Sprite.new(viewport)
        @display.bitmap = Bitmap.new(60, 24)
        @display.bitmap.font.size = 16
        @display.bitmap.font.color = Color.new(0, 255, 00)
      elsif @display != nil
        @display = @display.dispose
      end
    end
   
    alias frame_rate_update update
    def update
      frame_rate_update
      if @display != nil
        @display.bitmap.clear
        @display.bitmap.fill_rect(0, 0, 60, 24, Color.new(0, 0, 0, 96))
        @display.bitmap.draw_text(0, 0, 60, 24, self.frame_rate.to_s, 1)
      end
    end
  end
end
 
Graphics.toggle_display
[/rgss]

Here would be a generic example. Toggle it with "Graphics.toggle_display"

Well, thanks but I know how to make up some sprite. I just need VALUE.

BlueScope":2w32kghp said:
iirc, there's a method named Graphics.frame_rate that returns exactly that... in case I'm horribly mistaken (which is anything but out of the question), try looking up a support topic I opened up myself a while back where I got helped.

Sorry. That does not work, as I mentioned. It is static.

Also, There are another methods I tried By modifying the Graphics Module.

by using Time.now.
Code:
 

$timetemp = -1

module Graphics

  class << self

  alias_method(:screenshot_update, :update)

  def update(*args)

      if $timetemp < Time.now.sec

        $timetemp = Time.now.sec

        $debugsprite.bitmap.clear

        v = Graphics.frame_count % 40

        $debugsprite.bitmap.draw_outlined_text(0,0,200,20,v.to_s)

      end

      screenshot_update(*args)

  end

end

 

But this all does not work properly. Maybe I did something wrong on caculation.
 
Well in that case, just compare check frame counts every clock second.

Make an update method, set a variable to Time.now.
From here keep checking this, and when the next second passes, check how many frames have passed, then reset the initial value.
 

DJ

Some guy that did RMXP before
Member

ForeverZer0":10sjmer7 said:
Well in that case, just compare check frame counts every clock second.

Make an update method, set a variable to Time.now.
From here keep checking this, and when the next second passes, check how many frames have passed, then reset the initial value.
THAT gives me some idea. Then (current frame - frame 1 seconds before) would be good, right?
 
Yes, check the Time and store the current frame count. Check the time exactly one second later, using the Time class, not the Graphics module, and compare the current frame count to the one you stored to see how many actual frames have passed.
 

DJ

Some guy that did RMXP before
Member

Wow, That DID worked. Thanks, ForeverZer0 (It had a little difference, though). And also I find something useful on your signature -Dropbox, and your scripts. Thank you so much.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top