77ed2ccfb1
* update pxt.json files * Fix button event enums fixes https://github.com/microsoft/pxt-calliope/issues/206 * Fix Safari CSS Rule for iOS app fixes https://github.com/microsoft/pxt-calliope/issues/205 * aprove preffered repos should fix https://github.com/microsoft/pxt-calliope/issues/167
34 lines
891 B
Markdown
34 lines
891 B
Markdown
# If On Edge, Bounce
|
|
|
|
Make a [sprite](/reference/game/create-sprite) on the edge of the
|
|
[LED screen](/device/screen) bounce away.
|
|
|
|
```sig
|
|
game.createSprite(0, 2).ifOnEdgeBounce();
|
|
```
|
|
|
|
## Parameters
|
|
|
|
* a **sprite** that might be on the edge of the LED screen.
|
|
|
|
## Example
|
|
|
|
This program makes a sprite on the right edge of the screen with a
|
|
direction of 90 degrees, and bounces it so it has a direction of -90
|
|
degrees -- exactly the opposite direction.
|
|
|
|
```blocks
|
|
let ball = game.createSprite(4, 2);
|
|
basic.showNumber(ball.get(LedSpriteProperty.Direction));
|
|
input.onButtonEvent(Button.B, input.buttonEventValue(ButtonEvent.Down), () => {
|
|
ball.ifOnEdgeBounce();
|
|
basic.showNumber(ball.get(LedSpriteProperty.Direction));
|
|
});
|
|
```
|
|
|
|
## See also
|
|
|
|
[create sprite](/reference/game/create-sprite),
|
|
[is touching](/reference/game/is-touching),
|
|
[is touching edge](/reference/game/is-touching-edge)
|