Slider Widget
-
Introduction
You can add a slider widget to the stage to make it easy for the user to specify a value within a range that looks like this:
To do that, use the following block:- X and Y: you can set the position of the center of the slide using the X and Y parameters.
- Width: the width of the slider widget
- Minimum and Maximum Values: You can set the value range of the slider to be between a minimum value (like 0) and a maximum value (like 100). As the user slides the knob on the slider, the value will stay within this range.
- Name: give the slider a name so that you can refer to it later.
Set a Slider’s Value
You can set the value of the slider to a certain value after adding it. For example, this block would set the slider to the value of 50, in the middle between 0 and 100:
Read a Slider’s Value
To read the value selected by the user, you can use the reporter block “value of widget”:
When Slider’s Value Changes
To handle the event that the user is sliding the knob of the slider, you can use the “when widget changes” block:
Demo
In this program, we create a slider between 0 and 180, and set its value to 90 initially. Whenever the user slides the slider, we would update the direction of the apple sprite using the value of the slider.