Hi!
So lately I've been trying to make some very informative interfaces that will update very frequently, but I'm running into the natural performance issue of redrawing all the time. I've tried a lot of methods to make this work, but all my attempts result in a FPS loss of about 20-30 depending on the requirements in redrawing.
Basically I have this block inside my update method to make sure it only refreshes when necessary:
I've attached the 'draw_energy_bar' method below. Any input on this would be greatly appreciated!
As a note: it works exactly as I intend it to, except the FPS loss is so great it makes it unplayable. So I'd just like to understand how to do more CPU-friendly coding that prevents this for my own experience.
Thanks in advance!
So lately I've been trying to make some very informative interfaces that will update very frequently, but I'm running into the natural performance issue of redrawing all the time. I've tried a lot of methods to make this work, but all my attempts result in a FPS loss of about 20-30 depending on the requirements in redrawing.
Basically I have this block inside my update method to make sure it only refreshes when necessary:
Code:
# If bar values have changed: clear and refresh
if @hp != @actor.hp || @sp != @actor.sp || @energy != $game.system.energy
self.contents.clear
draw_energy_bar(8, 104)
end
Code:
#----------------------------------------------------------------------------
# * Draw Energy Bar
#----------------------------------------------------------------------------
def draw_energy_bar(x, y)
# Define bitmaps
container = System::BITMAPS['container']
barmap = System::BITMAPS['crisisbar']
# Draw container
self.contents.blt(x, y, container, Rect.new(0,0,container.width,container.height))
# Obtain percentage values
percentage = $game.system.energy.to_f / 100
if percentage <= 0
width = 0
else
width = barmap.width * percentage
end
# Draw healthbar
unless width <= 0
self.contents.blt(x, y, barmap, Rect.new(0,0,width,barmap.height))
end
# Get values
current = "#{$game.system.energy}"
nxt = "100"
self.contents.font.color = Color.new(255,255,255)
self.contents.font.outline = true
self.contents.draw_text(x, y-6, 96, 24, "Energy")
self.contents.draw_text(x + 4, y-6, 90, 24, "#{current}%",2)
self.contents.font.color = normal_color
self.contents.font.outline = false
end
As a note: it works exactly as I intend it to, except the FPS loss is so great it makes it unplayable. So I'd just like to understand how to do more CPU-friendly coding that prevents this for my own experience.
Thanks in advance!