This extension is fairly narrow in scope: it adds a special ‘status bar’ sprite, which can be used to manage statuses similar to to
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.
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.
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’.
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.
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.
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
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.
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.)
This gives you all the status bars of the given type; this is similar to
all sprites of kind.