by Forum_account
[Documentation] [Share] [Zip]
I updated the Overlays library to include a demo that's similar to the Stat Bar Overlays library. That library is really a demo and a library all in one. It provides some of the underlying functionality (being able to create, hide, and show overlays), but only provides that for stat bars.

By using the Overlays library to create stat bars you get all of the easy ways to manipulate overlays that the library provides. You can change a stat bar's position, icon, layer. You can also easily control who the stat bar is visible to. It's very easy to make your health meter only visible to people in your party, or, in an RTS, make health meters on your units that are visible only to you.

The demo I added uses a slightly different approach than the other library. I prefer to define things this way:

parent_type = /StatBar

stat_name = "health"
max_name = "max_health"

icon = 'overlays-demo-icons.dmi'
num_states = 15
state_name = "health-bar-"


// shift the overlay down 7 pixels

// to create the health meter:
mob.health_meter = new /HealthMeter(mob)

Instead of this way:

mob.health_meter = new /bar_overlay(mob, 'health-bar.dmi', 15, "health", "max_health", pixel_y = -7, state_prefix = "health-bar-")

The second approach has the definition of the health bar's properties in the same place where you're using the health bar. The first example gives you a separate place for defining the properties of the health meter. That way, if they get more complex, it doesn't complicate the code that simply uses the health meter.

Also, by creating a custom object type to be your health meter, you can add additional procs (or override existing ones) to change how it works. When every stat bar uses the /bar_overlay type, you're stuck with the same behavior for each one.
An arrow through my heart, sir. An arrow through my heart. ;)

Although I like how you automatically determine the num_states if it's unspecified. That's pretty handy.