Trying to create click and dragging in AGS [SOLVED]

Started by Gold Dragon, Thu 03/07/2008 02:05:57

Previous topic - Next topic

Gold Dragon

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.
Code: ags

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?
Want to see how I am doing and how far I've gotten in my game? Visit my forum  http://www.freepowerboards.com/DragonKnight

Gilbert

Haven't tested, but this may work.

Code: ags

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


Khris

Further improvement:
Code: ags
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.

Gold Dragon

OOOOOOOoooooo Even better!!!!!!!


Thanks Guys!!!!   ;D ;D ;D
Want to see how I am doing and how far I've gotten in my game? Visit my forum  http://www.freepowerboards.com/DragonKnight

naltimari

Just a quick question: now that the Wait(1) is there, no_loop_check is not really necessary anymore, is it?

SMF spam blocked by CleanTalk