1
\$\begingroup\$

I know how to place the items you see in the picture, my problem is how do I move them? How do I know if the player is swiping right or left? I made the items with a ds_list in a script file and then have an object obj_MenuCreation run that script, so if I move the obj_MenuCreation, will it move the list with it?

\$\endgroup\$
1
\$\begingroup\$

Assuming you're using the Device Input functions, finding out if the user is swiping left or right shouldn't be much hard.

In the documentation, about the function device_mouse_x(), it says that the returned value "for mobile devices (...) will only be updated while the screen is being touched". You can use this function in a Step Event to get the last x value of the mouse (the finger on mobile devices).

Let's say we have two variables, cur_x_new and cur_x_prev, and we updated them in a Step Event as follows:

// Step event - Update cursor input
cur_x_prev = cur_x_new;
cur_x_new = device_mouse_x(0);

We can then define three different cases:

  • Equal values: the user isn't moving the finger on the screen or, more likely, they aren't even touching the screen at all;
  • New value greater than previous: the user moved the finger towards right since the last update;
  • New value smaller than previous: the user is moving the finger towards left.

The swiping "speed" can be calculated as cur_x_new - cur_x_prev, and you can also check for this value to be at least greater than a threshold, otherwise you can assume no swipe action is occurring.

Edit Once you know whether the user is swiping, you can move the sprites by drawing them at coordinates + offset, where offset is a clamped value that increases/decreases depending on the swiping direction.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .