Dragging in specific areas only?

Non-platform specific questions.

Dragging in specific areas only?

Postby brandov » Tue Nov 04, 2008 11:48 pm

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:
Hi! I've been using Game Editor since it came out, but I am shy and don't post much on the forums!
http://www.vivianvideo.com
User avatar
brandov
 
Posts: 6
Joined: Wed Oct 03, 2007 10:43 pm
Location: Michigan, USA
Score: 0 Give a positive score

Re: Dragging in specific areas only?

Postby Killagram » Wed Nov 05, 2008 4:08 am

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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
-Brian W. Kernighan
User avatar
Killagram
 
Posts: 31
Joined: Sun Aug 10, 2008 8:49 pm
Score: 5 Give a positive score

Re: Dragging in specific areas only?

Postby Kalladdolf » Wed Nov 05, 2008 10:23 am

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.
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: Dragging in specific areas only?

Postby brandov » Thu Nov 06, 2008 3:05 am

alright, i tried it and it worked, now i'll just tweak it to match the size of the inventory box. thanks :D
Hi! I've been using Game Editor since it came out, but I am shy and don't post much on the forums!
http://www.vivianvideo.com
User avatar
brandov
 
Posts: 6
Joined: Wed Oct 03, 2007 10:43 pm
Location: Michigan, USA
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron