Customisable Horizontal Bar Creator
Posted: Mon Oct 22, 2012 3:17 am
Hi there all.
Just wanted to share this Global Code for creating Horizontal Bars.
Basic Information
You can customise the size, change colors of border, background and bar. You don't need any images because its uses the canvass actor with all the draw functions. Once you've added the global code you can update the hBar anywhere from your other events (i.e. when HP changes for enemies or players, or whatever...) or create additional canvass actor for more bars (or even use clones). Any way here's all the info. Hope you guy's find it useful
The Global Code
Use Instructions
I suppose you could add more fancy images over these (or use Draw From function) to create more stylish looking bars. I decided to keep things simple for now thou.
Just wanted to share this Global Code for creating Horizontal Bars.
Basic Information
You can customise the size, change colors of border, background and bar. You don't need any images because its uses the canvass actor with all the draw functions. Once you've added the global code you can update the hBar anywhere from your other events (i.e. when HP changes for enemies or players, or whatever...) or create additional canvass actor for more bars (or even use clones). Any way here's all the info. Hope you guy's find it useful
The Global Code
- Code: Select all
void hBar (int barValue, int barMax, int barHeight, int border_R, int border_G, int border_B, int back_R, int back_G, int back_B, int fill_R, int fill_G, int fill_B)
{
int bar_i=0;
// Check valid bar values
if (barValue <0)
{
barValue=0; // if value negative set to 0
}
else
{
if (barValue>barMax)
{
barValue=barMax; // if value larger then barMax set to barMax
}
}
// Clear old display
erase(0,0,0,1);
// -------------------- Create Background ----------------------
setpen(back_R, back_G, back_B, 0.0, 1);
moveto(0, 0);
for(bar_i = 0; bar_i < barMax+2; bar_i++)
{
moveto(bar_i, 0);
lineto (bar_i, barHeight);
}
// -------------------- Create Border ---------------------------
setpen(border_R, border_G, border_B, 0.0, 1);
moveto (0, 0);
lineto (barMax+1, 0);
lineto (barMax+1, barHeight);
lineto (0, barHeight);
lineto (0, 0);
// -------------------- Create Value Bar ------------------------------
setpen(fill_R, fill_G, fill_B, 0.0, 1);
moveto(1, 1);
for(bar_i = 1; bar_i < barValue+1; bar_i++)
{
moveto (bar_i, 1);
lineto (bar_i, barHeight-1);
}
}
Use Instructions
I suppose you could add more fancy images over these (or use Draw From function) to create more stylish looking bars. I decided to keep things simple for now thou.