This tutorial will teach you how to make touch movement controls where horizontal swiping on one side of the screen controls the movement of the character, and vertical swiping on the other side makes them jump. And both movements can happen, at the same time.
I found this to be a nicer way of controlling movement than the on screen buttons or joysticks that others prefer. And I couldn't find a tutorial for it online, so I decided to make one. The tutorial is compiled of bits of code from lots of different places.
This tutorial will require you to be able to test over a local network on a mobile device.
Setting up the project
First open a new, standard project. Add another layer. On the bottom layer make two big rectanglular sprites, like below. The left one is named "leftfinger" and the right one is named "rightfinger." These sprites dictate which area of the screen is to be used for horizontal movement, and which area for jumping.
Ensure that the layer's parallax is set to 0,0. This will stop the controls from moving with the character as it travels through the level.
In the top level add some "solid" sprites, the blocks, and a small sprite character. Give the Character sprite the "platform" behaviour. And then insert the Touch Input. Add another small, block shaped sprite and give it a JumpThru behaviour.
Add three new Global Variables and the following events.
This means that from the second you touch the screen, it tracks your movement and depending on which side of that intial touch you move your finger, the character will move left and right. The parameters should be small enough so that you're not swiping your finger over the entire screen to make it move, but big enough that you can stop, if you want to.
If you were to test this on your mobile device now, the character could move from side to side.
Add another three Global Variables, and some more events!
This works in a similar way to the horizontal movement; it tracks your finger's movement but on the Y axis as opposed to the X axis.
So now you can run the layout and see how your character can move, jump, and fall. But only one at a time, which is useless but leads us to Touch IDs.
Adding touch IDs
First add two new variables. They both have the value of -1 and will be used to store TouchIDs.
Then add two events, which set the new variables to the ID number of each touch, as each individual touch generates a unique number and we need the game to know which touch is the one to listen to.
Finally change each action relating to Touch.Y and Touch.X to Touch.YforID(TouchRightID) and Touch.XforID(TouchLeftID). Add a condition to only allow the movement if the Touch ID variables are above 0, and an action to set them back at -1 when the screen is no longer being touched.