GameMaker Tutorial - Drag Objects
Vložit
- čas přidán 8. 09. 2024
- Get Element Earth ▶ tinyurl.com/hga...
Support this channel ▶ tinyurl.com/jet...
Follow me on Facebook ▶ tinyurl.com/opj...
Follow me on Instagram ▶ / jp_damstra
Follow me on Twitter ▶ / slasherxgames
Follow me on Google+ ▶ plus.google.co...
Here's a very simple way to drag objects around the game room using the mouse.
▼ Useful Links and Resources ▼
GameMaker Studio Project File ▶ tinyurl.com/jez...
▼ More ▼
General Game Maker Playlist ▶ tinyurl.com/omg...
Game Maker Networking ▶ tinyurl.com/oau...
Want a reliable file hosting service to easily share files over the cloud? Get Dropbox here: db.tt/5J3viPHd
Hey, every user who signs up using the above link gets an extra 500MB of storage!
Happy Coding :D
9 years later and 100+ updates top game maker and this STILL worked for me. Cheers!
Thank you for this video!
I've been looking for a tutorial on this feature for so long.
You're welcome!
@@SlasherXGAMES - This is exactly what I was looking for as well. Thank you so much!
Thank you Im super surprised this still works in 2022!
That's a better way to do than what I have tried before. Thanks!
This is PERFECT for what I'm working on!
Thank you I think this is still relevant!
Tysm!
It's possible to click on more than one of them, then all the items under the mouse will move. I'd like to find a way to stop that from happening.
thanks, great man
thanks alot, great tutorial :)
Simple and useful, thanks!
amazing
Thank you for this
How can I make it snap to a 32x32 grid after I release the mouse? Im making a grid based game and will look odd and wont work if its not alligned
Thanks a lot!
Thanks! That helped me a lot!
How can I get this to work in a physics room? I want to interact with dropping and positioning blocks...like Jinga
+
thank you!
every time an object with this code is under something else with the same code, it seems to pick both up. Can someone fix the problem?
varible states
Nice!
thank you for gamemaker video
Nice.. Thanks
When you place one object on top of another, and then select one, it will pick them both up. Is there a way to make it only select the one on top?
+Curtis Smith This is the only problem I've found with this tutorial. I've found a solution to this. You create a variable called draggable. This will check whether the object should be dragged or not. then you make a variable like this:
dis = distance_to_point(mouse_x,mouse_y)
this will be run in the step event.
then you add a collision event with the code:
if dis< other.dis
{
draggable = true
other.draggable = false
}
else{
draggable = choose(true,false)
if draggable == true
{
other.draggable = false
}
else{
other.draggable = true
}
}
This will set the draggable of the object to true if the mouse is the closest to the object.
Then you edit the left pressed event to first check if draggable is true, and if so, drag = true.. etc.
Finally you add a "Global left pressed" event and simply say, draggable = true
Hope this helped!
+Mickaly13 X I was thinking about coming back to this project and this will certainly help me out :) Thanks!
+Curtis Smith No problem, I'm glad I could help! :)
can you make a sliding puzzle with this?
randomize() , that's the code I'm looking for, thanks!
I try to make this with physics, but does not work, if I no use physics work, but i need physics, how I made do be? (sorry my english is very bad)
Thank you for your tutorial. I have the problem that the game sometimes won't recognizej the release of the mouse button and the mouse cursor keeps on dragging the object until I click again.
Hi I changed the code so I can only move the picked object in x, the problem is my mouse get out of the object in y then don't release the object when I release the mouse, there is any instruction to lock the mouse in x coordinate when I keep the LMB pressed?
How do I solve the problem when I tried to drag a single object it just drag the other objects along the way too, when I drag it past the other objects? Like it pick up everything along the way of dragging.
my x y syntax is a bit different to you but it is similar to a snap to grid, even though I hadn't use the move_snap function for it.. They're working . And I'm using GML 2.0
Can You Please Fix It, Because When Ever I Drag The Potions With My Mouse. It Creates Potions Like A Trail.
DBreader Hi there,
Compare the video demonstration and downloadable project file to your code to find your problem.
Ok, Thanks.
Do you have a color set as your background? You have to have a background for this effect to work.
Very usefull ! Thanks. I still have a question : when you release the object, it come back to depth = 0. Imagine i have 3 objects and i want to pile it one above the others, how can i do to always have the last released object on top of the others ? Thanks for yours answers :-)
depth = -y;
How to make it so its specific objects and not randomize in the create event
Hello can you do a Update video? Like if you are clicking on a obj then go to a antother room
if the object im trying to move is set with physics i can not interact with them in game any advice?
how do I make a drag object move only inside an empty box with walls?
SlasherXGAMES ™
- How do you make the potions go back to its original location after mouse release?
- How to add effects to the potions?
Achid Rashid There are two variables that hold the starting point of the instance on game start: xstart and ystart.
Move them back to these positions. Explore the GameMaker effects system. It can be a lot to digest at the beginning and will take a bit of time to create the effect you desire.
Thanks
How do you drag object while the view is moving
PERFECT !
How would you make it an object instead of a sprite?
how do I get it to snap to a grid once dropped?
Lets say your grid is 32x32 pixels in size:
if !place_snapped(32, 32) {
move_snap(32, 32);
}
can i make it so i can drag it anywhere but on a object i choose? so like, i can drag a box around in a house, but cant drag it out of the walls?
DJ Duck Jojnes maybe collision with Wall then stop grab?
Great video, thanks! How do you randomize six sprites but make it so that only one can appear? So all of the six sprites will appear every time just in different places?
You'll have to keep tabs on which sprites have already been drawn.
You could do the following:
var number = irandom(6);
switch (number){
case 0: //draw potion 0
var alreadyExists = false;
with (obj_draggable)
{
if (sprite_index == spr_potion0)
{
alreadyExists = true;
}
}
if (!alreadyExists)
{
with (instance_create(some x, some y, obj_draggable)
{
sprite_index = spr_potion0;
}
}
break;
case 1: //draw potion 1
//repeat as in case 0, but test against an instance having spr_potion1;
break;
etc...
}
Hope that helps.
Can u help me with how to drag an object only up and down.
AKUL AGARWAL Ignore any variables to do with changing the x coordinate. Namely xx in the Create event and xx = x - mouse_x in Left Pressed and x = mouse_x + xx in Step :)
How do you make the dragable objects snap to a grid?
For future people, he explains this in a different video
czcams.com/video/LJbMuHq5UrE/video.html
How do I make the potions snap to the nearest e.g 10x 10y
2 years old comment... if you don't mind a reply:
Add in the step event: x = 10*(x div 10); y = 10*(y div 10);
EDIT: That will snap to the nearest LOWER value; the fix is simple tho: use (x+5 div 10) instead of (x div 10)
3:40
i understood nothing -.-
Thank you!!