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.

Whats the best workaround to clearing and redrawing a bunch of crap?

Good day everybody!

What is the easiest workaround to BIG refresh methods... like, in my situation, my Advanced Debug Menu draws every switch/variable in its own page, but changing their value requires clearing EVERYTHING and redrawing it again, and again, and again while the value is being changed.

Well, since the switch/variable Names and ID's don't change, they don't need to be redrawn, or cleared, during the process of changing a value, only the value itself needs to be redrawn. Sure, if all 5000 were showing, there'd still be some kinda lag maybe, but it would be greatly reduced by not having to redraw the non-changing items. I've split the methods up, between drawing the text for things such as switch names, variable names, actor settings, player settings, etc. and their respective values... but when it all comes down to it, it still leads to a self.contents.clear and everything has to be redrawn again anyway.

So, what would you suggest to workaround not refreshing the stuff that doesn't need to be refreshed, and refreshing their modified values only? It wouldn't be a big deal, except changing one variable in 5000 would be a time consuming process as all 5000 are redrawn each time the value of ONE variable is changed.
 
Fastest way would be to just use the fill_rect method, and only clear certain areas. If you are doing something with drawing the change of switches and variables, you may also want to duplicate the classes to watch for changes. Like so:

Code:
class Window  
  # blah blah blah
  def refresh
    global_refresh = false
    if @game_variables == nil || @game_switches == nil
      global_refresh = true
      @game_variables = $game_variables.dup if @game_variables == nil
      @game_switches = $game_switches.dup if @game_switches == nil
  end
  for i in 1..999
    # if global refresh, need to draw variable names and switches because they haven't drawn yet
    if global_refresh
      # Now, where you draw the variable/switch names, clear where you plan to draw this
      self.fill_rect(draw_x, draw_y, draw_width, draw_height, Color.new(0, 0, 0, 0))
      self.fill_rect(draw_x, draw_y, draw_width, draw_height, text, align)
    end
    # Now, if global refresh or variable change
    if global_refresh || @game_variables[i] != $game_variables[i]
      @game_variables[i] = $game_variables[i]
      # Do the same thing here as drawing the name
    end
  end
end

That should pretty much do the trick.
 
In case I didn't specify, call the refresh method every frame like update, but...

You could make this faster by only calling the refresh method every x frames.

Code:
  def update
    if Graphics.frame_count % x == 0
      refresh
    end
  end

Replace x with the number of frames between redraws.
 

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