Scratching my head on an algorithm for this too....
1) Ryex idea. It would be easy to write a method that subtracts (draws transparent) a line from the image. Then depending on the difference between the current & new value, iterate between the two. If the precision is a percent (100 possible values), and the value changes from 100 to 99, you draw 3 or 4 lines from the center of the circle at angles 0, 1, 2, 3.6. The problem with this is I think the edges would end up jagged looking unless you added some kind of anti-alias algorithm, which would slow down the execution.
2) multiple images on layers. What if we broke the top image up into 4 separate images (quadrants). Make 6 separate sprites (background, gauge1(100 - 75%), gauge2, gauge3, gauge4, and another upper left quadrant of the background). then rotate each sprite to partially hide it behind the next sprite. The last sprite, the partial background would turn on (become visible) when the value is less than 25%, for gauge4 to hide behind.
3) Make the top image like a big character set (except 10 x 10) with a separate image for each percent value, then just .blt the appropriate cell for the new value.
This will do the last option. It actually needs an image that's 10 x 11. first row starts with 0 & ends with 9. 11th row just has 100 in the first cell. (101 images in all)
Cells can be any size. Call it with @hp_gauge = Sprite_
HPgauge.new(actor_id, x, y)
Don't forget to also dispose & update it in whichever scene you add it to.
#==============================================================================
# ** Sprite_HPgauge
#------------------------------------------------------------------------------
# This sprite is used to display an hpgauge.
# Create an image 10 cells wide, 11 cells tall with the gauge at 0%
# in the first cell, the gauge at 100% in the first cell of the 11th row.
#==============================================================================
class Sprite_HPgauge < Sprite
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(actor_id, x = 0, y = 0)
super()
@charset = RPG::Cache.picture("hpgauge")
@cw = @charset.width / 10
@ch = @charset.height / 11
self.bitmap = Bitmap.new(@cw, @ch)
self.x = x
self.y = y
self.z = 500
self.visible = true
@actor_id = actor_id
@hpp = -1
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if @hpp != $game_actors[@actor_id].hp * 100 / $game_actors[@actor_id].maxhp
@hpp = $game_actors[@actor_id].hp * 100 / $game_actors[@actor_id].maxhp
row = @hpp / 10
col = @hpp % 10
rect = Rect.new(col * @cw, row * @ch, @cw, @ch)
self.bitmap.blt(0, 0, @charset, rect)
end
end
end