The Daily Click ::. Forums ::. Klik Coding Help ::. Help make an object mouse dragable from the spot I click on
 

Post Reply  Post Oekaki 
 

Posted By Message

dov



Registered
  14/07/2005
Points
  15
23rd August, 2005 at 14:01:29 -

I have a routine which lets me drag an object with a mouse.
I set the objects x an y position to the mouses x an y position when i click it.
However each time I click it it jumps to its corner.
I want to be able to grab it in whatever spot I click and then drag it.

 
n/a

EleXor



Registered
  21/01/2003
Points
  269
23rd August, 2005 at 14:44:44 -

you could try somethng like:
x pos = set x pos to xmouse - / + value
y pos = set y pos to ymouse - / + value

 
n/a

Noyb



Registered
  31/05/2004
Points
  1117

VIP Member
23rd August, 2005 at 14:51:10 -

You'll need to store the initial x and y offsets.

Code:
User clicks with left button on Active & counter isDragging = 0:
+Set Active's internal flag 0 on
+set Alterable value A to X("Active") - XMouse
+set Alterable value B to Y("Active")- YMouse
+Set counter isDragging to 1.

Repeat while left mouse-key is not pressed:
+Set Active's internal flag 0 off
+Set counter isDragging to 0

Active's internal flag 0 is on:
+Set Active's x position to XMouse + Alterable Value A
+Set Active's y position to YMouse + Alterable Value B

Example file(TGF): http://bellsouthpwp.net/r/e/realnoyb/MouseDrag.gam
Example file(MMF): http://bellsouthpwp.net/r/e/realnoyb/Mousemove.cca

Of course, you'll probably want to add stuff that restricts the player from dragging the objects off the screen, or if you want it to pick up the top piece instead of the bottom.

Image Edited by the Author.

 
"Omg. Where did they get the idea to not use army guys? Are they taking drugs?" --Tim Schafer on originality in videogames

EleXor



Registered
  21/01/2003
Points
  269
23rd August, 2005 at 15:39:23 -

By the way why do you have to use 'flags'?
In that case I would have used 'set alt value a to 1'

 
n/a

Noyb



Registered
  31/05/2004
Points
  1117

VIP Member
23rd August, 2005 at 15:52:06 -

Well, I just use flags whenever a boolean expression is used, when a condition is either true or false. Using flags isn't required, but it just seems simple and natural to me. It frees up space for you to use other alterable values, which is important with TGF's paltry three alterable values at least.

 
"Omg. Where did they get the idea to not use army guys? Are they taking drugs?" --Tim Schafer on originality in videogames
   

Post Reply



 



Advertisement

Worth A Click