|
| 1 | +# attach To Sprite |
| 2 | + |
| 3 | +Attach a status bar to a sprite. |
| 4 | + |
| 5 | +```sig |
| 6 | +statusbars.create(0,0,StatusBarKind.Health).attachToSprite(null) |
| 7 | +``` |
| 8 | + |
| 9 | +A status bar is attached to a sprite you specify. |
| 10 | +The status bar will follow the sprite around the screen instead of being set in a fixed position. |
| 11 | + |
| 12 | +When a status bar is attached to a sprite, you can use the `status bar attached to mySprite` |
| 13 | +and `sprite that statusbar is attached to` blocks to get the sprites / status bars that are attached to each other. |
| 14 | + |
| 15 | +## Parameters |
| 16 | + |
| 17 | +* **toFollow**: the sprite to attach to. |
| 18 | +* **padding**: an optional [number](types/number) of pixels to pad around the status bar. |
| 19 | +* **offset**: an optional [number](types/number) of pixels away from the sprite to place the status bar. |
| 20 | + |
| 21 | +## Example |
| 22 | + |
| 23 | +```blocks |
| 24 | +let statusbar = statusbars.create(20, 4, StatusBarKind.Health) |
| 25 | +let mySprite = sprites.create(img` |
| 26 | + . . . . . . . . . . b 5 b . . . |
| 27 | + . . . . . . . . . b 5 b . . . . |
| 28 | + . . . . . . b b b b b b . . . . |
| 29 | + . . . . . b b 5 5 5 5 5 b . . . |
| 30 | + . . . . b b 5 d 1 f 5 d 4 c . . |
| 31 | + . . . . b 5 5 1 f f d d 4 4 4 b |
| 32 | + . . . . b 5 5 d f b 4 4 4 4 b . |
| 33 | + . . . b d 5 5 5 5 4 4 4 4 b . . |
| 34 | + . b b d d d 5 5 5 5 5 5 5 b . . |
| 35 | + b d d d b b b 5 5 5 5 5 5 5 b . |
| 36 | + c d d b 5 5 d c 5 5 5 5 5 5 b . |
| 37 | + c b b d 5 d c d 5 5 5 5 5 5 b . |
| 38 | + c b 5 5 b c d d 5 5 5 5 5 5 b . |
| 39 | + b b c c c d d d 5 5 5 5 5 d b . |
| 40 | + . . . . c c d d d 5 5 5 b b . . |
| 41 | + . . . . . . c c c c c b b . . . |
| 42 | + `, SpriteKind.Player) |
| 43 | +controller.moveSprite(mySprite) |
| 44 | +statusbar.attachToSprite(mySprite) |
| 45 | +``` |
| 46 | + |
| 47 | +```package |
| 48 | +pxt-status-bar=github:jwunderl/pxt-status-bar |
| 49 | +``` |
0 commit comments