Scratch – Sprite Movement using a Touchscreen

Many tutorials on how to create a game in Scratch will be based on using the arrow keys to control the main sprite. This is a great approach indeed but is not suitable if you are designing the game toe be used on a tablet or smartphone. In this case, your input device to control the main sprite is not the keyboard but the touchscreen.

The following short tutorial will show you how you can control the movement of your sprite (in this case the cat) using a touchscreen. The idea will be to create two other sprites/buttons called Arrow_Left and Arrow_Right that, when clicked using a mouse or tapped using a touchscreen will tell the cat sprite to move in the relevant direction.
scratch-touchscreen-sprite-movement
You can recreate this code online using the scratch website.

Step 1: Right ArrowStep 2: Left ArrowStep 3: Main SpriteStep 4: Up & Down

Step 1: Arrow_Right Sprite


scratch-new-sprite
You will need tot create a new sprite and use the arrow sprite from the scratch library.
scratch_arrow_sprite

You should rename this sprite “Arrow_Right”.

You will then need to add the following code to this sprite to detect when the user clicks or taps on this sprite:
scratch-arrow-right-code

Step 2: The Arrow Left


Repeat the instructions from Step 1 to create another arrow sprite and call it “Arrow_Left”. The code for this new sprite will be as follows:
scratch-arrow-left-code

You will also need to change the costume of this sprite to show an arrow pointing to the left:
scratch-arrow-costume

The main sprite (in this case the cat, will need to move left or right when it receives the messages “left” and “right”. To do so we will use the following code (on the cat sprite):
scratch-cat-sprite-left-right
You can repeat the above steps to create an Arrow_Up and a Arrow_Down sprite if it is relevant to your game.

Did you like this challenge?

Click on a star to rate it!

Average rating 3.6 / 5. Vote count: 40

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!