GameMaker Checking Gestures - quick question

S

SVG

Guest
Am I wrong is assuming that you cannot check in code an event of a gesture without having to do it from the "Add Event?" For example I want to check if a "Flick" gesture occurred in my step event, can it be used similar to checking a keyboard press or mouse click in code?
Code:
if keyboard_check_pressed(vk_enter) {}

if event_flick {}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
In code, doing a flick event is a bit more complex than doing it in the events... You have to first register the touch, then get the initial x/y position, then detect the release, then calculate the difference in distance between the touch and release and then finally set the instance speed/direction. Something like this:

Code:
// CREATE
startx = 0;
starty = 0;
moving = false;

// STEP
if device_mouse_check_button_pressed(0, mb_left) // Check for touch event
{
// Get touch event position
var _mx = device_mouse_x(0);
var _my = device_mouse_y(0);
if instance_position(_mx, _my, id) // Check if the touch was on the instance
    {
    // Initialise the flick
    moving = true;
    startx = _mx;
    starty = _my;
    }
}

if moving // Move the instance with the touch
{
var _mx = device_mouse_x(0);
var _my = device_mouse_y(0);
if device_mouse_check_button_released(0, mb_left)
    {
    var _dist = point_distance(startx, starty, _mx, _my);
    speed = _dist / 10; // set the speed - change 10 for whatever feels right!
    direction = point_direction(startx, starty, _mx, _my);;
    moving = false;
    }
else
    {
    // Optional... move the instance with the touch position
    x = _mx;
    y = _my;
    }
}
As you can see, it's a fair bit of code, and if you want to do this for multiple touches, you have to wrap it all in a "for" loop and use arrays for each finger! This is why the gesture events were added in GMS2... :)
 
Last edited:
S

SVG

Guest
In code, doing a flick event is a bit more complex than doing it in the events
I really appreciate the time and attention you put into this, and in the long run I may actually need that and it will same me lots of time. Though my thought is simply this:
Game Maker 2 already runs functions to check if something occurred and should have a call or built-in-variable (whatever) that returns true or false of that event, like collision detection events, a lot of the time I need to check if a collision occurred in my Step even in the middle of my code so it runs another code at the proper time. If I used the built collision Event then it would be too late. There should easily be something to see if a "flick" or "pinch" etc. occurred for the Step Event. I could have easily just made my own variable in the Gesture Event "Flick" and turned that custom variable to true, but the problem is that my Step Event, and even Step End Event, have already run for that frame and I would have to check the custom variable next frame for my Step Event which will be too late. Not sure if I'm making sense, but if there is no simple way or built in variable to pull a bool like that then I would have to resort to using your function up top in my step event before my other code, which seems very redundant since GM2 already checks if it were done or not, does this make sense?

Anyways Thanks a ton again!
 
Top