GameMaker Tutorial - Drag Objects

Sdílet
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

Komentáře • 68

  • @FireLordJD
    @FireLordJD Před 7 měsíci +2

    9 years later and 100+ updates top game maker and this STILL worked for me. Cheers!

  • @jasmin_kreativ5147
    @jasmin_kreativ5147 Před 4 lety +4

    Thank you for this video!
    I've been looking for a tutorial on this feature for so long.

    • @SlasherXGAMES
      @SlasherXGAMES  Před 4 lety

      You're welcome!

    • @Dancing_Cow_909
      @Dancing_Cow_909 Před 3 lety

      @@SlasherXGAMES - This is exactly what I was looking for as well. Thank you so much!

  • @pivotskits5400
    @pivotskits5400 Před rokem

    Thank you Im super surprised this still works in 2022!

  • @Gamewwx
    @Gamewwx Před 10 lety +2

    That's a better way to do than what I have tried before. Thanks!

  • @PloxCleveringa
    @PloxCleveringa Před 9 lety +1

    This is PERFECT for what I'm working on!

  • @sirhultzilop8824
    @sirhultzilop8824 Před 4 měsíci

    Thank you I think this is still relevant!

  • @winterboard3590
    @winterboard3590 Před 2 lety +1

    Tysm!

  • @memoryman15
    @memoryman15 Před 3 lety +2

    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.

  • @Max-ko8fm
    @Max-ko8fm Před 4 lety +1

    thanks, great man

  • @dracula5752
    @dracula5752 Před 5 lety +1

    thanks alot, great tutorial :)

  • @Visionsofmortality
    @Visionsofmortality Před 10 lety

    Simple and useful, thanks!

  • @gametheater4197
    @gametheater4197 Před 3 lety +1

    amazing

  • @GDBlackRed
    @GDBlackRed Před 4 lety

    Thank you for this

  • @25greengoblin
    @25greengoblin Před 8 lety +1

    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

  • @domino-kids
    @domino-kids Před 2 lety

    Thanks a lot!

  • @tobiasbrugel424
    @tobiasbrugel424 Před 7 lety

    Thanks! That helped me a lot!

  • @Troylglover
    @Troylglover Před 7 lety +4

    How can I get this to work in a physics room? I want to interact with dropping and positioning blocks...like Jinga

  • @peruano9187
    @peruano9187 Před 3 lety

    thank you!

  • @koreboredom4302
    @koreboredom4302 Před 8 lety +6

    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?

  • @sora-ec8si
    @sora-ec8si Před 7 lety +1

    Nice!

  • @larryteslaspacexboringlawr739

    thank you for gamemaker video

  • @suryana3124
    @suryana3124 Před 6 lety +1

    Nice.. Thanks

  • @KurtisBlack
    @KurtisBlack Před 9 lety +3

    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?

    • @ywoogikim365
      @ywoogikim365 Před 8 lety +3

      +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!

    • @KurtisBlack
      @KurtisBlack Před 8 lety

      +Mickaly13 X I was thinking about coming back to this project and this will certainly help me out :) Thanks!

    • @ywoogikim365
      @ywoogikim365 Před 8 lety

      +Curtis Smith No problem, I'm glad I could help! :)

  • @phillipPbor
    @phillipPbor Před 8 měsíci

    can you make a sliding puzzle with this?

  • @AF1Gaming
    @AF1Gaming Před 6 lety

    randomize() , that's the code I'm looking for, thanks!

  • @kuelho1615
    @kuelho1615 Před 4 lety

    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)

  • @DarkD33p
    @DarkD33p Před 4 lety

    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.

  • @PedroSilva-zn1lp
    @PedroSilva-zn1lp Před 6 lety

    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?

  • @Arcyriea
    @Arcyriea Před 4 lety

    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.

    • @Arcyriea
      @Arcyriea Před 4 lety

      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

  • @dbreader7853
    @dbreader7853 Před 9 lety +2

    Can You Please Fix It, Because When Ever I Drag The Potions With My Mouse. It Creates Potions Like A Trail.

    • @SlasherXGAMES
      @SlasherXGAMES  Před 9 lety

      DBreader Hi there,
      Compare the video demonstration and downloadable project file to your code to find your problem.

    • @dbreader7853
      @dbreader7853 Před 9 lety

      Ok, Thanks.

    • @blasterisk
      @blasterisk Před 8 lety +1

      Do you have a color set as your background? You have to have a background for this effect to work.

  • @studiok7662
    @studiok7662 Před 8 lety +1

    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 :-)

  • @jaybrown6725
    @jaybrown6725 Před 7 lety

    How to make it so its specific objects and not randomize in the create event

  • @ludvigesbjornsson6814
    @ludvigesbjornsson6814 Před 8 lety

    Hello can you do a Update video? Like if you are clicking on a obj then go to a antother room

  • @th3r3ap3r2
    @th3r3ap3r2 Před 6 lety

    if the object im trying to move is set with physics i can not interact with them in game any advice?

  • @sandrah4566
    @sandrah4566 Před 6 lety

    how do I make a drag object move only inside an empty box with walls?

  • @DAK2DINNER
    @DAK2DINNER Před 9 lety

    SlasherXGAMES ™
    - How do you make the potions go back to its original location after mouse release?
    - How to add effects to the potions?

    • @SlasherXGAMES
      @SlasherXGAMES  Před 9 lety

      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.

    • @DAK2DINNER
      @DAK2DINNER Před 9 lety

      Thanks

  • @abdalla1823
    @abdalla1823 Před 9 lety

    How do you drag object while the view is moving

  • @gekoghost806
    @gekoghost806 Před 8 lety +1

    PERFECT !

  • @grassythegrassblock3281

    How would you make it an object instead of a sprite?

  • @tuckertcs
    @tuckertcs Před 8 lety +1

    how do I get it to snap to a grid once dropped?

    • @yokmp1
      @yokmp1 Před 7 lety

      Lets say your grid is 32x32 pixels in size:
      if !place_snapped(32, 32) {
      move_snap(32, 32);
      }

  • @redcubegames5905
    @redcubegames5905 Před 7 lety

    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?

    • @supermangris8705
      @supermangris8705 Před 7 lety

      DJ Duck Jojnes maybe collision with Wall then stop grab?

  • @relicanth101
    @relicanth101 Před 7 lety

    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?

    • @SlasherXGAMES
      @SlasherXGAMES  Před 7 lety +1

      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.

  • @akul101
    @akul101 Před 9 lety

    Can u help me with how to drag an object only up and down.

    • @SlasherXGAMES
      @SlasherXGAMES  Před 9 lety

      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 :)

  • @MrVideosnatcher
    @MrVideosnatcher Před 8 lety

    How do you make the dragable objects snap to a grid?

    • @jasonp7091
      @jasonp7091 Před 2 lety

      For future people, he explains this in a different video
      czcams.com/video/LJbMuHq5UrE/video.html

  • @VendettaGames2015
    @VendettaGames2015 Před 9 lety

    How do I make the potions snap to the nearest e.g 10x 10y

    • @Anonymous-jo2no
      @Anonymous-jo2no Před 6 lety

      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)

  • @joshuajackson296
    @joshuajackson296 Před 7 lety

    3:40

  • @felipepeharo2017
    @felipepeharo2017 Před 7 lety

    i understood nothing -.-

  • @user-hm9wn2sw6x
    @user-hm9wn2sw6x Před 5 lety

    Thank you!!