GMS 2 How to Detect when a Player Holds Down on the Screen

Hi all!

I'm currently in development of a game for Android and iOS devices. In it, you control a character's speed as it orbits around a circle. Because it's for mobile devices, I want to have very little controls. So, I made tapping the screen control the speed and holding down on the screen is supposed to be how you shoot your gun.

I began fooling around with the built-in gesture events and I noticed that the "Tap" event doesn't work after you start to hold down. I've tried the other gesture events and setting some alarms to time how long the player taps to no avail. :eek:

I've searched far and wide through these forums and online and have seen nothing concerning this. Is this even possible?

Help is greatly appreciated!!

Thanks!!
 
I'm not familiar at all with mobile gaming, so this is just taken from the manual (and GMS 1, so hopefully it's not different)

Code:
device_mouse_check_button(device, button);
This is the mobile equivalent for continually pressing a button? According to the manual it registers every step.

Whereas this alternative only registers once for the press (and is presumably what you're using?)

Code:
device_mouse_check_button_pressed(device, button);
So: If you were using the first - as long as it registers true you add to a variable. Then test to see if its over a certain amount - if it is, you know it has been held down long enough to fire. When you register the button being released you reset the variable to zero.
 
Although they are mouse functions, this is from the section regarding mobile input. In GMS 1 I don't think it had specific events for mobile touchscreen input, so the above would be the code used.

If GMS 2 has specific mobile events, and has the equivalent of this:
Code:
device_mouse_check_button(device, button);
and it didn't work, then that may be due to setting an alarm within the event. The problem with doing that (using an alarm) is that it only starts counting down once the event that triggered it is no longer true. Because this function is active for every step (remaining true), the alarm will be called every step. It is constantly reset, and won't do anything until the condition becomes false and it can run without interruption.

Do the process again before the alarm has counted down, and it will be reset again. That is why adding to a variable, for as long as the screen is touched, is better than setting an alarm. Because it can have its value added to while the condition holds true.

Code:
if device_mouse_check_button(device, button)
{
if alarm[0] == -1
{
alarm[0] = whatever
}
}
Using an alarm with the above would work, because of the condition checking to see if the alarm is at -1. The alarm only has this value when it has fully counted down, or is currently inactive. If it has a value of anything else then the condition cannot allow it to be reset.

Code:
if device_mouse_check_button(device, button)
{
is_count ++
if is_count > whatever
{
do whatever;
is_count = 0;
}
}
else
{
is_count = 0;
}
Both examples above would be doing the same thing, but I think the second method is slightly better. As using alarms seems to have a higher cost performance wise.
 

Yal

šŸ§ *penguin noises*
GMC Elder
With custom counter variables, you also can have as many as you want - there's only a certain limit of alarms.

And yes, the touchscreen inputs are mapped to the mouse events for mobile platforms. Keep in mind that there's no mouse hovering, though, so events like Mouse Enter / Leave won't work properly and the behaviour for what happens to mouse_x / mouse_y when there's no touching is a bit different.
 
Top