How to Click & Drag Objects with the Mouse
Submitted:|| 1st December, 2008
MAJOR EDIT: Clickteam has now implemented the "click and drag" movement for Active Objects in MMF2. There is no need for additional code; simply select the object you want to be able to click and drag, go to the Movement tab, and select "Click and Drag" from the drop-down menu of movement options. There's no coding needed!
I'm leaving the article posted here, if just for the sake of including the note above.
I found a handful of articles or forum topics that addressed how to click and drag objects with the mouse, but didn't feel any of the examples were detailed enough to help a novice quickly and easily. I've created an example (with MMF2) that includes several comments to help explain this concept in easy-to-understand words.
To sum up:
Create your Active Objects and assign the same Qualifier to each of them.
Create a Counter that will mark the status of mouse clicks.
Create code that indicates when the user has clicked on an object, and which object is clicked, so that the Object is linked to the mouse cursor when the button is depressed.
Create code that turns off the effect once the player lets go of the mouse button.
KNOWN LIMITATIONS (for advanced users): This code automatically snaps the Active Object's center point to the mouse cursor; it is not designed to maintain the mouse cursor at the point where the user has clicked. I figured having a bug-free click and drag process was more important than pixel-perfect mouse clicking, at least for this example. Furthermore, I'm not interested in coding all that, as this example currently meets my needs for a project in the works. If anyone wants to come up with an example that allows for exact placement of the mouse cursor at the same point the user clicks on it, feel free to add it in a comment here (or elsewhere in TDC).
Thanks to the coders who pointed me in this direction, most recently some comments from Assault Andy (I think). Hopefully you've found this example useful. Enjoy!
You can download the example at the following link:
UPDATE: Take a look at Mr_Tom's code here, and see how to click-and-drag from any point on the object, using only three events. The basic principles are the same as above, and it appears to work flawlessly:
Thanks for the codesmithing, Mr_Tom!
UPDATE: as mentioned below, there is an extension that allows you to click and drag Active Objects. You can download this extension from the ClickTeam forums at the following link: