pxt-calliope/docs/reference/game/if-on-edge-bounce.md
Galen Nickel 3f106307ff
Fix some titles, sigs in ref docs ()
* Fix some title and sigs in ref docs

* better buffer source
2019-06-05 16:28:56 -07:00

851 B

If On Edge, Bounce

Make a sprite on the edge of the LED screen bounce away.

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.

let ball = game.createSprite(4, 2);
basic.showNumber(ball.get(LedSpriteProperty.Direction));
input.onButtonPressed(Button.B, () => {
    ball.ifOnEdgeBounce();
    basic.showNumber(ball.get(LedSpriteProperty.Direction));
});

See also

create sprite, is touching, is touching edge