So I've been working on a script to allow players (and enemies) to be able to use a skill and add a barrier that blocks all damage until you take out the barrier. I have the barrier part working, and the skill to add the barrier working. However, I'm stuck on how to draw a bar on screen to show how much HP the barrier has left. Can someone help point me to the right classes/methods I'll need to use in order to do this? I haven't yet been able to figure out how the base battle system ever draws its bars, so maybe if someone could explain that to me I'd be set?
How do I draw HP bars in battle?
● ARCHIVED · READ-ONLY
-
-
Look at how Window_Base draws HP gauges.
-
It looks like it uses draw gauge from what I see. So in theory, if I create a new window for this barrier bar, and add in the draw gauge commands (and of course call them when needed) it should work?
-
look at draw_gauge.
-
What do you mean by add in the draw gauge commands? You shouldn't need to add any of the commands into your code; if you subclass Window_Base or any of Window_Base's subclasses, your window class will inherit the methods already. For instance:
class MyWindow def refresh c1 = Color.new(0,0,0,255) c2 = Color.new(255,255,255,255) draw_gauge(0, 0, contents.width, 100.0, c1, c2) endendclass OtherWindow < Window_Base def refresh c1 = Color.new(0,0,0,255) c2 = Color.new(255,255,255,255) draw_gauge(0, 0, contents.width, 100.0, c1, c2) endendmy_win = MyWindow.newyour_win = OtherWindow.newmy_win.refresh #=> error! undefined variable or method draw_gauge for MyWindowyour_win.refresh #=> no error.MyWindow doesn't inherit any other class' properties / methods, as it doesn't have a parent class. However, OtherWindow's parent is Window_Base, so everything defined in Window_Base is visible / usable in OtherWindow. This is why the code works in OtherWindow#refresh.Another note, if you wish to change a few things in the method, you can call super in the method, and it'll execute the classes parent's method, like so:
Code:As you might see, the execution will be:class A def letter "A" end def print_letter STDOUT << letter endendclass B < A def letter "B" end def next_letter "C" end def print_letter super STDOUT << next_letter endendA.new.print_letterB.new.print_letter
Code:This is a semi-incomplete example, but it serves it's purpose, and any holes in it will help you learn by figuring them in yourself. I would look up a few explanations on Ruby inheritance. :)ABC -
That helps. For some reason I was thinking a bar would be its own window class, and couldn't find it. Now I know to just create my own, and inherit the base. I think I can proceed from here now.
Edit: Yep, it worked. Problem solved. Can close as solved.