Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: SilverWizard_OTF on Tue 29/06/2004 09:24:13

Title: Drag and Drop function?
Post by: SilverWizard_OTF on Tue 29/06/2004 09:24:13
Hello, i would like to know if there is a way to create a drag and drop function with AGS.  For example, it would be great if the player coulld click  an object, and move it everywhere he wants, and then to leave it somewhere.

I would be grateful if anyone could  give me some information about that.
Title: Re: Drag and Drop function?
Post by: Gilbert on Tue 29/06/2004 09:42:25
Yes, actually I'd done similar things with it, but that involves some scripting.

What I'd done was basically use a variable to keep track on whether it's in drag mode, say, call it dragging, and another variable, say, dragobject to keep track of the object number being dragged, like define it on top of the script:
int dragging, dragobject;
and put something like below in repeatedly execute:

if (IsButtonDown(LEFT)) {
Ã,  if (dragging) SetObjectPosition(dragobject,mouse.x,mouse.y);
Ã,  Ã,  else {
Ã,  Ã,  Ã,  Ã, dragobject=GetObjectAt(mouse.x,mouse.y);
Ã,  Ã,  Ã,  Ã, if (dragobject>=0) dragging=1;
Ã,  Ã,  Ã, }
Ã,  } else dragging=0;

note that this code is very rough and yet to be tested, you may need to polish it to suit your needs.

-- EDIT -- verified that it's working

Title: Re: Drag and Drop function?
Post by: SilverWizard_OTF on Tue 29/06/2004 09:57:06
Thank you, i will try these right now
Title: Re: Drag and Drop function?
Post by: Scummbuddy on Tue 29/06/2004 16:07:11
might try this link that is in the Technical Archive: http://www.agsforums.com/yabb/index.php?topic=9963.0
Title: Re: Drag and Drop function?
Post by: Gilbert on Wed 30/06/2004 02:20:04
They're a bit difference, seems that the one you mentioned was click then drag, but my code was for HOLD and drag. The code may benefit if that baseline changing part is incorporated though.
Title: Re: Drag and Drop function?
Post by: SilverWizard_OTF on Wed 30/06/2004 10:57:50
Thanks very much all of you!  There is only one small problem, that with the code that scummbuddy said, when the player clicks  the object (only just clicks it), it is moving a little, something that will make the player to suspect the trick.
  In my game i didn't want when the player just clicks the object, to be moved, but when he clicks and DRAG, then to move it.
  But it is ok,  this code is fine.

Again thanks for your help.