Click and Drag Mechanic

0 favourites
From the Asset Store
Click! Click! 136 click sounds for your video games or media projects
  • Hi guys,

    New to Construct 2 and the forums. I'm using to prototype some things right now. I searched and didn't find anything so I figured I'd ask.

    Is there a way I can add a click and drag mechanic to my game?

    For example, I want to be able to take a sprite and drag it into a another sprite, and have them lock together at a specific position.

    Any help is appreciated.

  • I would say... have an event: if cursor is over object AND mouse button is down. Then the action would be set position at mouse.x and mouse.y.

  • This mechanic is used and described in the example capx for the pathfinder behavior.

    Edit: also it starts as squiddster descirbed just above.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you sqiddster and Kyatric!

    That's pretty much what I wanted. Except when I created two separate events for two separate objects, they ended up locking together.

  • Can you post a capx, or describe a bit more how you set up your project, what happens and what you expected to happen ?

    You can check in the PathFinder behavior the way it is done is by making sure that the drag/drop will "happen" if no other drag/drop is "happening" already.

  • The capx isn't complicated at all

    The issue actually happens with your demo as well (http://dl.dropbox.com/u/36472942/construct/plugin/release/pathfinder/demo/index.html)

    If you click and drag either the S or D around, it works fine. But if you're dragging the S and it moves over the D, they will both lock together because the project will register your mouse being over both the original sprite and the one you're moving over.

  • Oh that was a bug. Nice catch.

    Redownload the capx, I edited it.

  • I probably already know the answer to this but...I downloaded the capx and tried opening it and got all sorts of error codes regarding Behavior type uses unknown ID in event file such and such.

    I am assuming this may be because there are 100+ events and I am using the free version r58.

    Is anyone with the full version running into the same issue though? Or do I have to install the path finder behavior in order to run this capx?

  • May try this behavior plugin:drag & drop

    The drag&drop will pick the topmost(max zindex) instance if overlapping.

  • You have to install the PathFinder Behavior.

    Also I must admit I did not thought about free edition, the capx contains 5 layers.

    I don't know if this will prevent loading or not.

    Let me know.

  • I followed the instructions on your page step by step. I even had to create the behaviors folder, as there wasn't one included with the default files with r58. Then I unpacked the contents of your zip into that folder. I still got the error code. I will take a screenshot when I get home and PM it to you. It indicates an error line.

    Just out of curiosity. I notice this was a caproj file. Do you have it on a capx? I have had no issues with capx files yet. (knock on wood)

  • I don't have enoug Rep to PM you so here is the error code:

    <img src="http://www.mypwn.com/construct2/error.png" border="0" />

  • I followed the instructions on your page step by step. I even had to create the behaviors folder, as there wasn't one included with the default files with r58.

    This bugs me. In your installation of C2 R58 you didn't had a folder "behaviors" in "C2_basefolder\exporters\html5", you had to create it ?

    If so, you couldn't use 8direction, bullet, scrollto behaviors and others.

    If you still had access to those, then you copied the pathfinder in the wrong place.

    I'd suggest you to uninstall C2 and install r59 at any rate then.

    Just out of curiosity. I notice this was a caproj file. Do you have it on a capx? I have had no issues with capx files yet. (knock on wood)

    The link I provide in the PathFinder topic is to PFDemo.capx, not caproj.

    Anyway, a .capx is a compressed .caproj (project folder). (You can open .capx files in 7zip for example)

    Install R59 and follow the steps again.

    Make sure the pathfinder files are in "C2\exporters\html5\behaviors\pathfinder" and then open the capx.

    It should work.

  • Installed r59. Yes, I had to create the folder. It's still giving that error code though.

    c2project\object-folder\object-type\behaviors\behavior-type

    Line 21, Column 17

    If I assume correctly this is pointing to the runtime js file on which line 21 reads

         behaviorProto.Type = function(behavior, objtype)

    I will delete the files, re-download, unpackage in the behavior folder and give it another try.

    I have the paid version now so that rules out the +100 events possibility.

  • Line 21

    {

              this.behavior = behavior;

              this.objtype = objtype;

              this.runtime = behavior.runtime;

         };

    ? <img src="smileys/smiley5.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)