Page 1 of 1

Dragging in specific areas only?

PostPosted: Tue Nov 04, 2008 11:48 pm
by brandov
is there a way to code something so that you can drag inside of a specified area, but no where else?
like say, just inside a box with sides a couple pixels thick.

Or, at the very least, have it so if they drag it out, have it snap back in when they let go of the mouse? I've been trying to figure this out, because i want them to be able to reorganize items in their inventory, but not have them be able to put them just randomly floating outside of it. throw your ideas at me :lol:

Re: Dragging in specific areas only?

PostPosted: Wed Nov 05, 2008 4:08 am
by Killagram
there are many ways to do this. The more specific you can be, the better an answer you will recieve.

One method is to say, on object, mousebuttonup, if(distance(x,y, box.x, box.y)<n(MoveTo(Event Actor, box.x, box.y etc. etc. etc.)} else (MoveToEtc) Which will put it outside the box if they drag it far enough away, and back in the box if they didn't move it far enough away. However, the way you stated it, you didn't specify if they even CAN move it away. This is also a simple method which doesn't include what happens if there's already something else inside the box.

As i said, many, many, many ways.

Re: Dragging in specific areas only?

PostPosted: Wed Nov 05, 2008 10:23 am
by Kalladdolf
I think the most effective way to drag in specific areas only is NOT to use the drag event, but the FollowMouse function on the mouse button down event, stop it on the mouse button up event.
Then you enter the following code for the actor:
Code: Select all
if(x > 100) {x = 100;} // in this case 100 is the limit coordinate
if(x < -100) {x = -100;}
if(y > 100) {y = 100;}
if(y < -100) {y = -100;}

right. this way you limit the area from x-100 to 100 and from y -100 to 100.
I'll give you a demo if you have problems with it.

Re: Dragging in specific areas only?

PostPosted: Thu Nov 06, 2008 3:05 am
by brandov
alright, i tried it and it worked, now i'll just tweak it to match the size of the inventory box. thanks :D