How can I invert a gauge? So that It dont drop from right to left but from left to right?
Invert a Gauge
Learning Ruby and RGSSxLook at how the existing gauges are done and then just think about what it means to go from left to right.
You're changing the (x,y) AND width, height based on the percentage not just the width/height.
You're changing the (x,y) AND width, height based on the percentage not just the width/height.
Depends on how you are drawing the gauge. If via bitmaps from a folder, just blt from right to left, same width, etc. If you are manually generating it, then you have to find the difference in widths.
For instance we take the default method:
Well, we wanna flip it, so we find the difference in the max width of the bar, and the ratio it's currently at, then add that to the x coordinate of the gradient bar, like so:
For instance we take the default method:
def draw_gauge(x, y, width, rate, color1, color2) fill_w = (width * rate).to_i gauge_y = y + line_height - 8 contents.fill_rect(x, gauge_y, width, 6, gauge_back_color) contents.gradient_fill_rect(x, gauge_y, fill_w, 6, color1, color2) end
Code:
def draw_flipped_gauge(x, y, width, rate, color1, color2) fill_w = (width * rate).to_i gauge_y = y + line_height - 8 dif = width - fill_w contents.fill_rect(x, gauge_y, width, 6, gauge_back_color) contents.gradient_fill_rect(x + dif, gauge_y, fill_w, 6, color2, color1) end
Original thread: https://forums.rpgmakerweb.com/threads/invert-a-gauge.18291/