• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Visual [SOLVED] Drag and Drop an object?

C

corwin

Guest
Question..

1. How do I drag and drop an object in Game Maker 2 using the drag and drop feature (not coding).
My attempt: I selected the event Key Press - Left and not sure what to attach to it and how to make move to the event Key-Up Left.

2. How do these events play out on iOS and Android?
Does Key Press - Left count as me pressing my finger down on mobile?

Thanks!
 
C

corwin

Guest
Okay I figured out that "Snap Position" works with the mouse_x and mouse_y to drag and drop an object. It is a bit laggy. Please help me answer question two regarding iPhone and Android movement. Does "Left Down" for mouse count as a key press on mobile?
 

Neptune

Member
I have no idea how to use drag and drop. But i can provide some really simple code.
In the object(s) that are being "dragged": add a step event, and add this code:
Code:
if mouse_check_button(mb_left) && position_meeting(mouse_x,mouse_y,id)
{
x = mouse_x;
y = mouse_y;
}
If you decide to try the coding alternative -- this bit of code will have the object follow the mouse when you click-drag-release (or virtual mouse in mobile).
 
P

PandaPenguin

Guest
Okay I figured out that "Snap Position" works with the mouse_x and mouse_y to drag and drop an object. It is a bit laggy. Please help me answer question two regarding iPhone and Android movement. Does "Left Down" for mouse count as a key press on mobile?
if you aim for a mobile version better have a look at this first: device input
 
C

corwin

Guest
I have no idea how to use drag and drop. But i can provide some really simple code.
In the object(s) that are being "dragged": add a step event, and add this code:
Code:
if mouse_check_button(mb_left) && position_meeting(mouse_x,mouse_y,id)
{
x = mouse_x;
y = mouse_y;
}
If you decide to try the coding alternative -- this bit of code will have the object follow the mouse when you click-drag-release (or virtual mouse in mobile).
This worked well and much more smooth. Thank you.


if you aim for a mobile version better have a look at this first: device input
Thank you for this, very helpful.
 
J

Johnnyt123

Guest
if mouse_check_button_pressed(mb_left) && position_meeting(mouse_x,mouse_y,argument0)
{
argument0.move_item = 1
}
if !mouse_check_button(mb_left)
{
argument0.move_item = 0
}

if argument0.move_item == 1
{
argument0.x = mouse_x;
argument0.y = mouse_y;
}

argument0 is the first argument of your script. Here my script is called scr_DragDrop.
So in your object, you would write scr_DragDrop(id).
Ths is my version of the Drag and Drop inspired of the other replies here.
You must create a variable named move_item in your object or parent object for this code to work.
 
Top