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.
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
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.
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
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