Using mouse control
Alternatively, we could use the mouse to control the red bar and give the mouse the freedom to move all around the stage.
Here's how we could go about doing this.
Getting ready
To get started, we'll need to take our program from the end of the last recipe and eliminate the arrow key controls; this way we can focus on the mouse controls.
In the userBar
sprite, delete all three scripts that we have. Now we're ready to go!
How to do it...
-
Drag over a block to the script area for
userBar
. Insert a forever loop below the top hat block we just placed.
Inside the forever loop, place a go to () block from the Motion category.
Using the drop-down menu in the new block you just dragged over and select the mouse-pointer option.
Your code should look like the following set of blocks:
Now give playing your game a shot!
How it works...
The code for this recipe is much simpler than our last recipe. It starts when we have the green flag clicked, which initiates a forever loop. From there, the...