How to set Seekbar to jump in Sketchware App?

The Seekbar, which has recently been added to Sketchware in it's latest version, has opened a wide range of possibilities for android app development.

Here I will describe how the Seekbar can be converted into a jumping object.

1. Start a new project in Sketchware. In the view area, first insert a Linear(V) and set it's width and height to match parent. Inside that insert a Linear(H), and a Seekbar into that Linear(H). Note that maximum width of Seekbar is 100.

Set the top margin of this Linear(H) to 200 and set it's rotation to 270.

2. Insert another Linear(H) below the previous one, and inside that insert a Button. Set the top margin of this Linear(H) to 160 and set it's gravity to center_horizontal.

3. Now in Logic area add a new Timer component named time.

4. Add a new number variable named t. Also add a new block named Jump.


5. On activity create set t=0, and disable Seekbar.
 6. Then define Jump. Use TimerTask time after 10ms. Inside that set Seekbar progress, increase t by 1, and set the timer to stop after 1 jump.

7. To define the jump, we have to set the progress of Seekbar similar to the height of an object thrown vertically up in air under a gravitational field.

Here the maximum value (100) of Seekbar is the maximum height or distance and t is time. Initial velocity is v, and final velocity at maximum height is 0.

We know from laws of motion that:
              h=vt - (1/2)gt*t
and       v*v=2gh.

We will use the formula defining h to set the progress of Seekbar, and repeat it every 10ms to make it look continuous.

We know that maximum value of Seekbar is 100, therefore, from the second equation shown above, v*v/2g should be equal to 100. Take any value of v and g which satisfy this criteria and use them in the first equation shown above to set the motion of the progress bar.

The image below shows the codes to be used in Sketchware.

7. In the end, on Button click, insert the new block Jump.

8. Save and run your app, you will see the jump off Seekbar each time you press the button.

Here is a video of how to create the app described above.

Comments

Popular posts from this blog

Simple car racing android game in Sketchware

Creating a Drawing View in Sketchware

Enable Fullscreen for Youtube videos in WebView

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware