Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Gold Dragon on Thu 03/07/2008 02:05:57

Title: Trying to create click and dragging in AGS [SOLVED]
Post by: Gold Dragon on Thu 03/07/2008 02:05:57
ok I'm trying to script a puzzle where the user clicks on the piece of the puzzle and then drags it to where its supposed to go.

I have this code.

function noloopcheck oScroll1_Interact(){
  while(mouse.IsButtonDown(eMouseLeft)){
    oScroll1.X = mouse.x;
    oScroll1.Y = mouse.y;
  }
}


But I can't figure out how to update the screen while "dragging" the the item. I click and drag the item but it doesn't show that it moved until I release the left mouse button. Any ideas?
Title: Re: Trying to create click and draging in AGS
Post by: Gilbert on Thu 03/07/2008 02:08:37
Haven't tested, but this may work.


function noloopcheck oScroll1_Interact(){
  while(mouse.IsButtonDown(eMouseLeft)){
    oScroll1.X = mouse.x;
    oScroll1.Y = mouse.y;
    Wait(1);
  }
}

Title: Re: Trying to create click and draging in AGS
Post by: Khris on Thu 03/07/2008 08:30:52
Further improvement:
function noloopcheck drag(Object*o);
  int xa = mouse.x - o.X;
  int ya = mouse.y - o.Y;
  while(mouse.IsButtonDown(eMouseLeft)){
    o.X = mouse.x - xa;
    o.Y = mouse.y - ya;
    Wait(1);
  }
}

function oScroll1_Interact() {
  drag(oScroll1);
}

Now the piece won't jump when you pick it up.
Title: Re: Trying to create click and draging in AGS
Post by: Gold Dragon on Thu 03/07/2008 22:34:27
OOOOOOOoooooo Even better!!!!!!!


Thanks Guys!!!!   ;D ;D ;D
Title: Re: Trying to create click and draging in AGS
Post by: naltimari on Fri 04/07/2008 06:40:08
Just a quick question: now that the Wait(1) is there, no_loop_check is not really necessary anymore, is it?