pxt-calliope/docs/reference/input/on-gesture.md
2016-04-13 08:27:45 -07:00

983 B

On Gesture

Register an event handler that will execute whenever the user executes a gesture withthe BBC micro:bit.

input.onGesture(Gesture.Shake,() => {
})

Gestures

Example: random number

The following example displays a number from 0-9 on the screen when you shake the BBC micro:bit.

input.onGesture(Gesture.Shake,() => {
    let x = Math.random(10)
    basic.showNumber(x, 100)
})

Example: rock, paper, scissors

The following example shows one of three images (rock, paper, or scissors) when you shake the BBC micro:bit.

input.onGesture(Gesture.Shake,() => {
    let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
    img.showFrame(Math.random(3))
})

Lessons

bounce image, rock paper scissors