GameMaker Tutorial - Drag Objects

Поділитися
Вставка
  • Опубліковано 2 вер 2014
  • Get Element Earth ▶ tinyurl.com/hgadglg
    Support this channel ▶ tinyurl.com/jetb43t
    Follow me on Facebook ▶ tinyurl.com/opjtvq4
    Follow me on Instagram ▶ / jp_damstra
    Follow me on Twitter ▶ / slasherxgames
    Follow me on Google+ ▶ plus.google.com/+SlasherXGAMES
    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/jezawpn
    ▼ More ▼
    General Game Maker Playlist ▶ tinyurl.com/omg4xxs
    Game Maker Networking ▶ tinyurl.com/oauqu5y
    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

КОМЕНТАРІ • 68

  • @FireLordJD
    @FireLordJD 5 місяців тому +1

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

  • @jasmin_kreativ5147
    @jasmin_kreativ5147 4 роки тому +4

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

    • @SlasherXGAMES
      @SlasherXGAMES  3 роки тому

      You're welcome!

    • @Dancing_Cow_909
      @Dancing_Cow_909 3 роки тому

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

  • @PloxCleveringa
    @PloxCleveringa 9 років тому +1

    This is PERFECT for what I'm working on!

  • @Gamewwx
    @Gamewwx 9 років тому +2

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

  • @Visionsofmortality
    @Visionsofmortality 9 років тому

    Simple and useful, thanks!

  • @tobiasbrugel424
    @tobiasbrugel424 7 років тому

    Thanks! That helped me a lot!

  • @pivotskits5400
    @pivotskits5400 Рік тому

    Thank you Im super surprised this still works in 2022!

  • @dracula5752
    @dracula5752 5 років тому +1

    thanks alot, great tutorial :)

  • @sirhultzilop8824
    @sirhultzilop8824 2 місяці тому

    Thank you I think this is still relevant!

  • @GDBlackRed
    @GDBlackRed 4 роки тому

    Thank you for this

  • @user-hm9wn2sw6x
    @user-hm9wn2sw6x 5 років тому

    Thank you!!

  • @winterboard3590
    @winterboard3590 2 роки тому +1

    Tysm!

  • @DarkD33p
    @DarkD33p 4 роки тому

    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.

  • @Max-ko8fm
    @Max-ko8fm 4 роки тому +1

    thanks, great man

  • @sora-ec8si
    @sora-ec8si 7 років тому +1

    Nice!

  • @domino-kids
    @domino-kids 2 роки тому

    Thanks a lot!

  • @peruano9187
    @peruano9187 3 роки тому

    thank you!

  • @25greengoblin
    @25greengoblin 8 років тому +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

  • @suryana3124
    @suryana3124 6 років тому +1

    Nice.. Thanks

  • @larryteslaspacexboringlawr739
    @larryteslaspacexboringlawr739 6 років тому

    thank you for gamemaker video

  • @PedroSilva-zn1lp
    @PedroSilva-zn1lp 6 років тому

    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?

  • @memoryman15
    @memoryman15 3 роки тому +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.

  • @th3r3ap3r2
    @th3r3ap3r2 6 років тому

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

  • @gametheater4197
    @gametheater4197 3 роки тому +1

    amazing

  • @ludvigesbjornsson6814
    @ludvigesbjornsson6814 8 років тому

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

  • @AF1Gaming
    @AF1Gaming 6 років тому

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

  • @studiok7662
    @studiok7662 7 років тому +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 :-)

  • @grassythegrassblock3281
    @grassythegrassblock3281 7 років тому

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

  • @phillipPbor
    @phillipPbor 6 місяців тому

    can you make a sliding puzzle with this?

  • @abdalla1823
    @abdalla1823 9 років тому

    How do you drag object while the view is moving

  • @relicanth101
    @relicanth101 6 років тому

    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  6 років тому +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.

  • @Troylglover
    @Troylglover 7 років тому +4

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

  • @jaybrown6725
    @jaybrown6725 7 років тому

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

  • @kuelho1615
    @kuelho1615 3 роки тому

    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)

  • @sandrah4566
    @sandrah4566 6 років тому

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

  • @Arcyriea
    @Arcyriea 4 роки тому

    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 4 роки тому

      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

  • @KurtisBlack
    @KurtisBlack 9 років тому +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 8 років тому +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 8 років тому

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

    • @ywoogikim365
      @ywoogikim365 8 років тому

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

  • @koreboredom4302
    @koreboredom4302 8 років тому +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?

    • @Lyricsed
      @Lyricsed 6 років тому

      varible states

  • @DAK2DINNER
    @DAK2DINNER 9 років тому

    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  9 років тому

      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 9 років тому

      Thanks

  • @redcubegames5905
    @redcubegames5905 7 років тому

    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 6 років тому

      DJ Duck Jojnes maybe collision with Wall then stop grab?

  • @dbreader7853
    @dbreader7853 9 років тому +2

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

    • @SlasherXGAMES
      @SlasherXGAMES  9 років тому

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

    • @dbreader7853
      @dbreader7853 9 років тому

      Ok, Thanks.

    • @blasterisk
      @blasterisk 7 років тому +1

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

  • @tuckertcs
    @tuckertcs 8 років тому +1

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

    • @yokmp1
      @yokmp1 6 років тому

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

  • @VendettaGames2015
    @VendettaGames2015 9 років тому

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

    • @Anonymous-jo2no
      @Anonymous-jo2no 6 років тому

      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)

  • @gekoghost806
    @gekoghost806 7 років тому +1

    PERFECT !

  • @akul101
    @akul101 9 років тому

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

    • @SlasherXGAMES
      @SlasherXGAMES  9 років тому

      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 8 років тому

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

    • @jasonp7091
      @jasonp7091 2 роки тому

      For future people, he explains this in a different video
      ua-cam.com/video/LJbMuHq5UrE/v-deo.html

  • @joshuajackson296
    @joshuajackson296 6 років тому

    3:40

  • @felipepeharo2017
    @felipepeharo2017 7 років тому

    i understood nothing -.-