Skip to content

Commit

Permalink
More testing
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Nov 22, 2024
1 parent af81bae commit 995720f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
49 changes: 49 additions & 0 deletions docs/attach-to-sprite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# attach To Sprite

Attach a status bar to a sprite.

```sig
statusbars.create(0,0,StatusBarKind.Health).attachToSprite(null)
```

A status bar is attached to a sprite you specify.
The status bar will follow the sprite around the screen instead of being set in a fixed position.

When a status bar is attached to a sprite, you can use the `status bar attached to mySprite`
and `sprite that statusbar is attached to` blocks to get the sprites / status bars that are attached to each other.

## Parameters

* **toFollow**: the sprite to attach to.
* **padding**: an optional [number](types/number) of pixels to pad around the status bar.
* **offset**: an optional [number](types/number) of pixels away from the sprite to place the status bar.

## Example

```blocks
let statusbar = statusbars.create(20, 4, StatusBarKind.Health)
let mySprite = sprites.create(img`
. . . . . . . . . . b 5 b . . .
. . . . . . . . . b 5 b . . . .
. . . . . . b b b b b b . . . .
. . . . . b b 5 5 5 5 5 b . . .
. . . . b b 5 d 1 f 5 d 4 c . .
. . . . b 5 5 1 f f d d 4 4 4 b
. . . . b 5 5 d f b 4 4 4 4 b .
. . . b d 5 5 5 5 4 4 4 4 b . .
. b b d d d 5 5 5 5 5 5 5 b . .
b d d d b b b 5 5 5 5 5 5 5 b .
c d d b 5 5 d c 5 5 5 5 5 5 b .
c b b d 5 d c d 5 5 5 5 5 5 b .
c b 5 5 b c d d 5 5 5 5 5 5 b .
b b c c c d d d 5 5 5 5 5 d b .
. . . . c c d d d 5 5 5 b b . .
. . . . . . c c c c c b b . . .
`, SpriteKind.Player)
controller.moveSprite(mySprite)
statusbar.attachToSprite(mySprite)
```

```package
pxt-status-bar=github:jwunderl/pxt-status-bar
```
5 changes: 3 additions & 2 deletions pxtextension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace ml {
//% weight=50
//% parts="v2"
//% group="micro:bit (V2)"
//% help=github:pxt-microbit-ml/docs/on-start
//% help=github:microbit-foundation/pxt-microbit-ml/docs/on-start
export function onStart(event: MlEvent, body: () => void): void {
event.onStartHandler = body;
const wrappedBody = () => {
Expand All @@ -80,7 +80,7 @@ namespace ml {
//% weight=40
//% parts="v2"
//% group="micro:bit (V2)"
//% help=github:pxt-microbit-ml/README
//% help=github:microbit-foundation/pxt-microbit-ml/README
export function onStop(event: MlEvent, body: () => void): void {
if (!isRunning()) {
startRunning();
Expand All @@ -94,6 +94,7 @@ namespace ml {
//% draggableParameters="reporter"
//% parts="v2"
//% group="micro:bit (V2)"
//% help=github:pxt-status-bar/docs/attach-to-sprite
export function onStopDetailed(
event: MlEvent,
body: (duration: number) => void
Expand Down

0 comments on commit 995720f

Please sign in to comment.