Fox Studios logo Fox StudiosGame projects, devlogs and Scratch builds
Tutorials

How to Add Touch Controls to a Scratch Game for Phones

Someone posted their first platformer in the community thread last month and three of the first four replies said the same thing: it does not work on my phone. The game was fine.

A phone in landscape showing a Scratch platformer with round on screen arrow buttons under a player thumb

Someone posted their first platformer in the community thread last month and three of the first four replies said the same thing: it does not work on my phone. The game was fine. The player sprite moved with the arrow keys, which is what every tutorial teaches, and a phone has no arrow keys. Nothing on screen told the player that, so it looked broken.

That happens to almost every project that leaves the Scratch website and gets shared in a group chat. When we asked people in the last jam how they played the entries, a bit over half said phone or tablet. If you are sharing a link with friends, the odds are good that most of them will never touch a keyboard to play it. Adding touch controls takes about twenty blocks, and there is one limitation in Scratch that breaks the obvious approach, which is the part worth reading even if you have done this before.

Why the arrow keys do nothing on a phone

Scratch runs fine in a mobile browser. The green flag works, sprites move, sound plays. What does not exist is a keyboard, so every when right arrow key pressed block in your project sits there waiting for an event that will never arrive.

The blocks that do respond to a finger are the mouse blocks. A tap registers as mouse down? being true, and the touch position becomes the mouse x and mouse y. That means touching mouse-pointer?, distance to mouse-pointer and go to mouse-pointer all work on a phone exactly as they do with a mouse. Your whole control scheme has to be built out of those four blocks.

The when this sprite clicked block also fires on a tap, and beginners reach for it first. Skip it. It triggers once per tap and then stops, so a player holding their thumb on a move button gets a single step and nothing more. For movement you need a loop that checks whether the finger is still down.

Building the buttons, step by step

Start from a project that already works with the keyboard, because this method sits on top of what you have rather than replacing it. I will use a left button, a right button and a jump button.

  1. Draw the button. Make a new sprite with the paint editor. Draw a filled circle and put an arrow or the word Jump on it. In the editor, drag the corner handle until the shape reads about 70 by 70 in the width and height boxes at the top. Smaller than that and thumbs miss it, which is the single most common complaint we get in feedback threads.
  2. Place it where a thumb reaches. The Scratch stage runs from x of negative 240 on the left to 240 on the right, and from y of negative 180 at the bottom to 180 at the top. I put the left button at x negative 195, y negative 130, the right button at x negative 110, y negative 130, and jump at x 175, y negative 130. Corners, not the middle, because a finger in the middle of the stage covers the action.
  3. Add a broadcast on hold. In the left button sprite, use when green flag clicked, then forever, and inside that an if mouse down? and touching mouse-pointer? then wrapping broadcast move-left. Both conditions matter. Mouse down on its own fires wherever the player taps, and touching mouse-pointer on its own fires when the finger merely passes over.
  4. Give the button some feedback. Inside the same if block, add set size to 90 percent, and in an else branch set size to 100 percent. It is two blocks and it is the difference between a button that feels dead and one that feels pressed.
  5. Move the player from the broadcast. In the player sprite, add when I receive move-left followed by change x by negative 5, matching whatever number your arrow key script already uses. Do the same for move-right, and for jump point it at the script your up arrow already runs.
  6. Hide the buttons in the editor. Under the when green flag clicked in each button, add go to front layer and show. Front layer matters once you have a scrolling background, or the buttons disappear behind it on the second level.
  7. Keep the keyboard scripts. Leave every key pressed script exactly where it is. A project with both works on a laptop and a phone, and you do not have to maintain two versions.

Test it in the editor first by clicking and holding the mouse on a button. If the sprite creeps one step and stops, you used the clicked block somewhere instead of the forever loop.

The two finger problem nobody warns you about

Here is where the standard advice falls apart. Almost every guide tells you to add four arrow buttons and a jump button, and that looks right until a player tries to run and jump at the same time. They cannot. Scratch tracks exactly one pointer position, so a second finger either does nothing or steals the position from the first. Hold left, tap jump, and the left button goes quiet the moment your other thumb lands.

I have watched this ruin three jam entries. Two of them got reported as laggy, which they were not. The player was simply not receiving the movement they were asking for.

There are three ways around it and all of them are design changes rather than code tricks.

The first is the auto runner. The player moves forward on its own and the entire screen is one jump button, which is how most successful mobile platformers handle it. For a Scratch project this is usually a two minute edit: move the change x by 5 into the player's forever loop and delete the direction buttons entirely.

The second is steering with position instead of buttons. Put if mouse down? then point towards mouse-pointer, move 4 steps in the player's forever loop. One finger sets direction and speed at once. This works beautifully for top down games, maze games and anything with a chasing enemy, and it needs no buttons at all.

The third is a zone split. Treat the bottom half of the stage as a steering strip and the top half as the action. Check mouse y < negative 60 to decide whether a touch means move or means shoot, then use mouse x to pick a direction. It keeps two kinds of input without needing two fingers, at the cost of a slightly odd first thirty seconds for the player.

My own rule after helping with a lot of these: if your game genuinely needs simultaneous movement and action, make it keyboard only and say so on the project page. A clear note beats a control scheme that half works.

Two small things that still break it

Dragging a finger across the stage in a mobile browser scrolls the page, which means a steering gesture can send the whole project sliding up out of view. Full screen mode stops it. The fix is social, not technical: write Tap the full screen arrows first on the project page, right at the top of the instructions. We put that line on four jam entries and the complaints stopped.

The other one is contrast. A semi transparent grey button over a busy background is invisible on a phone in daylight. Use a solid fill with a dark outline, and check it outdoors once. If you are already drawing interface elements, the same sizing habits apply to the bar in how to make a health bar in Scratch.

Open your own project on a phone, not the editor preview. Then check four things: can you reach every button with one thumb while holding the phone, does the player keep moving while you hold, does anything important sit under where your hand rests, and can you start over without finding the green flag with a fingernail. That last one usually means adding a restart button of your own.

Then post it in the community thread and ask specifically which phone people used. We have had reports of a button working on Android and missing on an older iPad because of a sprite drawn slightly off centre in the paint editor. If you are still putting the first version together, the walkthrough in your first Scratch game covers the parts this one assumes, and the rest of the step by step guides are in tutorials.

FAQ

Can Scratch detect two fingers at once?

No. Scratch exposes a single pointer, so the second touch is ignored or replaces the first. Design around it with an auto runner, pointer steering or a zone split rather than trying to work around it in blocks.

Does when this sprite clicked work on touch screens?

It does, but only as a single tap. For anything that needs holding, use a forever loop with mouse down? and touching mouse-pointer? instead.

How big should a touch button be in Scratch?

Around 70 by 70 in paint editor units works for most thumbs on a phone held in landscape. Below about 50 the miss rate climbs fast, especially near the edges of the stage.

Will touch controls slow my project down?

Not measurably. Three button sprites each running one forever loop with two conditions is a tiny amount of work compared to drawing the stage. If a project slows after adding them, look for a loop without a wait block somewhere else.

DF
Diego Fenn

Diego covers finished builds and the community around them, and runs the feedback threads that shape what the studio makes next.

More posts by Diego

More in Tutorials

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven strcoding tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto