Microsoft MakeCode

Status Bars extension (beta)

This extension is fairly narrow in scope: it adds a special ‘status bar’ sprite, which can be used to manage statuses similar to to Lives and Score under Info. There is some overlap between this extension and the Sprite-data extension, in that they do similar things; if you just want to store data without anything showing up, you should use that extension instead.

Here’s an example of several ways of using status bars:

and here’s the extension itself:

Note that the status bar is actually just a special sprite; this means that you can use the blocks in the sprite category to manipulate it (e.g. change it’s position) if you want to!

This extension has a lot of blocks, so I’ll describe them in groups / feel free to ask questions about how things work if they don’t make sense. This one’s mainly just marked beta as I might adjust wording / etc as some of the blocks are slightly hard to describe in just a few words.

Create

This category just has a single block currently, for creating a status bar:

This creates a status bar sprite with the given dimension and status bar kind. The kind can change the starting colors of the sprite, but is otherwise there for you to change / interact with the events. One interesting note; the way the status bar fills and shrinks depends on the dimensions you give here: if you making it wider than tall, it will fill left to right; if it is taller than wide, it will grow up and down.

Value

This group is how you can change (or get) the value stored in the status bar. It also lets you change the max value; this is the value that corresponds to the status bar being ‘full’.

image

Attach

This section lets you attach the status bar to a sprite; and get the sprite a status bar is attached to / vice versa. If attached, a status bar will move along with the sprite, which can be helpful if you have a boss that needs a lot of damage to be destroyed / etc.

Display

This section has a lot of different options on how the status bar should look. These should ideally be self explanatory, but there are a few ones that I haven’t nailed the wording on quite yet / are more complicated.

The set statusbar smooth transition off has a number of different flags that change the behavior of the status bar. Each of them is described here: https://github.com/jwunderl/pxt-status-bar/blob/master/status-bar.ts#L1

The set statusbar position to left block has different behavior depending on if the status bar is attached to a sprite. If not attached, it will center the status bar on the given side of the screen. If the status bar is attached to a sprite, it will set which side of the sprite it is attached to.

set statusbar padding offset is definitely the block that is worded the worst, but I’m not sure on how to phrase it well: when the status bar is attached or positioned using the previous block, this determines the padding (how far away from the given side it is) and offset (positioning along the other axis). If anyone has suggestions for this one I’d love them; I’d suggest attaching the status bar to a sprite and trying a few different values to see how it works.

Events

These events help you interact with the status bar; the first will trigger when a status bar of the given type ‘runs out’ (e.g. when a sprite runs out of health, use this and sprite that statusbar is attached to to destroy that sprite), and the second one will occur whenever the status bar changes how it’s displayed (so that you can e.g. overlay text on the center of the status bar.)

Other

This gives you all the status bars of the given type; this is similar to all sprites of kind.

5 Likes

This is awesome! I love the empty event too. I feel like “full” could be pretty useful as well, like charging up something or completing an objective

1 Like

Yeah, i was thinking about a on x % event to be more general, was trying to figure out the proper semantics of that - e.g. maybe it should have a flag on whether its going over or under, so you can say “on under 50%, start boss phase 2” and have the event only trigger when going below after having been above 50 percent

Right. Maybe the standard <, >, <=, =>, ==, != comparisons would work? With a percent

1 Like

Love this!

1 Like

I’ve been waiting for something like this for forever!

So cool!

1 Like

Love this extension! Could the padding block be set statusbar offset_x 0 offset_y 0 instead and allow positive and negative values to determine which way it goes? It seems right now the padding and offset switch their meaning depending on horizontal vs vertical statusbars which confused me.