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.
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
Thank you, i will try these right now
might try this link that is in the Technical Archive: http://www.agsforums.com/yabb/index.php?topic=9963.0
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.
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.