Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Resources Consumption Meter
#7
(05-27-2023, 10:43 PM)kyonides Wrote: Since you mentioned a HUD, you might wanna learn how to easily implement a trigger that will properly update the HUD only once instead of every second or even a fraction of a second.

Code:
class MyHUD
  @@need_refresh = 0
  def self.need_refresh
    @@need_refresh
  end

  def self.need_refresh=(number)
    @@need_refresh = number
  end

  def update
    if @@need_refresh > 0
      refresh
      return @@need_refresh = 0
    end
  end
end

There were have a mock of a HUD, its update method only. (There are 2 other methods but we will ignore them for the time being.)

It will only redraw its contents IF and only IF the @need_refresh variable is equal to any number above 0. Once it got updated, it will set it to 0 so it can't be triggered over and over again.

How would you make sure it will ever update the stats when needed only?

Use something like the following:

Code:
class Game_Actor
  def hp=(new_hp)
    old_hp = self.hp
    super(new_hp)
    MyHUD.need_refresh = 1 if self.hp != old_hp
  end

  def sp=(new_sp)
    old_sp = self.sp
    super(new_sp)
    MyHUD.need_refresh = 2 if self.sp != old_sp
  end
end

As you can see, we are calling one of the unexplained methods of MyHUD class. It's a singleton method that calls a very specific class variable that can be used at any time, even from another classes or objects, i.e. from an actual Game_Actor alias one of the heroes!

That call will make sure that your HUD will only update itself when and only when the hero's HP or SP (or even both at the same time) activate it right after their values have changed.

By the way, I used a number instead of a boolean (true or false) because this way I do prevent the SP update to cancel an HP update for not having changed simultaneously.

That may be extremely helpful. I have no time to review it now, but I will do it eventually for sure.
My current HUD doesn't noticeably lag, but if I can make it even more efficient, count me in!
I will make a new post or edit this one once I will finish reviewing my HUD, I would paste it here for you to see, but it's full of my unskilled code, global variables, $game_switches and $game_variables, plus some extra graphical files. I think it would be annoying for you to even try to run it.
People here are really helpful, I'm amazed. One day, hopefully I can return the favor.
Reply }


Messages In This Thread
Resources Consumption Meter - by Whisper - 05-27-2023, 01:26 AM
RE: Resources Consumption Meter - by kyonides - 05-27-2023, 01:59 AM
RE: Resources Consumption Meter - by DerVVulfman - 05-27-2023, 04:52 AM
RE: Resources Consumption Meter - by Kain Nobel - 05-27-2023, 08:59 AM
RE: Resources Consumption Meter - by Whisper - 05-27-2023, 10:17 PM
RE: Resources Consumption Meter - by kyonides - 05-27-2023, 10:43 PM
RE: Resources Consumption Meter - by Whisper - 05-29-2023, 03:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Custom meter problem daylights 13 14,100 08-12-2013, 03:34 AM
Last Post: daylights



Users browsing this thread: