Drag and Drop function?

Started by SilverWizard_OTF, Tue 29/06/2004 09:24:13

Previous topic - Next topic

SilverWizard_OTF

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.
"All we have to decide is what to do, with the time that is given to us"

Gilbert

#1
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


SilverWizard_OTF

Thank you, i will try these right now
"All we have to decide is what to do, with the time that is given to us"

Scummbuddy

- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Gilbert

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.

SilverWizard_OTF

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.
"All we have to decide is what to do, with the time that is given to us"

SMF spam blocked by CleanTalk