Add Event, Action for Drag Drop obj_circle Object GameMaker

Step 7: Double click on obj_circle object add events, actions for it.

Step 8: To be able  to drag and drop this obj_circle in the game, we need 4 Basic Events Create, Event Step, Event Left Button, Event Glob Left Released and 6 Collision Events with color boxes.

Simple Drag Drop Object GameMaker Studio

 

On the right tabs - We click on Tab Control and select Action VAR - Set Variable. We will name this variable is drag and set the value for it is 0. ( It means when no drag yet, drag variable will be 0)

Drag Drop Object Game maker tutorials

 

In Left Button Event, we click on Tab Control and select Action VAR - Set Variable. We will name this variable is drag and set the value of it is 1. (means when we press the left mouse and hold it, the drag variable will be 1, so we can drag object obj_circle)

Simple Drag Drop Object in Game Maker Tutorial

 

In Step Event, We click on Control Tab and select Action If VAR Action. The Properties Popup will be displayed, we set the variable here is drag, value is 1 and operation is equal to. It means we will compare the variable drag; if the value is 1, so the obj_circle can be dragged.

Drag Drop Object GameMaker Tutorial

 

After adding the If VAR Action, we add Start of a block and End of a block Action. Between that block, we look at the Move Tab and select the Jump To Position Action.

Jump To Position, we will assign the x coordinate equal to mouse_x position, and y coordinate of the obj_circle object equal to mouse_y position. Just enter the mouse_x, mouse_y GameMaker will get the postion x, y of the mouse for us.

Drag Drop GameMaker Tutorial

 

In Glob Left Released Event, Game Maker Tutorial will add Var Action - Set Variable (again you can find this Action on the Control Tab on the right tabs list). We will set the variable drag is 0. (means when not holding the left mouse, the obj_circle object will be on the drop state so we are not be able to drag it anymore)

Simple Drag Drop GameMaker Studio

Put this obj_circle object to the room. Then, save it and try to run the game. Enter the mouse to obj_circle object and try to drag it. If the white obj_cricle object can drag following the mouse, so you've made it. If not, please review the tutorials steps above or leave the comment here so we can help you fix it.

Next steps, we will make the obj_circle change the color when moving and drop it to the color boxes.