How do I - Drag and Drop Problems

  • Hello all.

    I'm having a bit of an issue with the way that drag and drop works. In the game I am prototyping, you are supposed to be able to drag an object and place it onto the same object in order to create a bigger version. In doing so, both objects should be deleted and a different object spawned where the original was.

    I can get the drag n' drop functionality to work, but no matter what I try I cannot get the spawning/deleting to work properly. The closest I've been able to get is the spawning of the new object and deletion of ONE object, but not both that were involved in the collision. The event chain I've used to do so is shown below:

    Any and all help would be appreciated.

  • condition > On drop

    action > call function

    condtion > on function

    sub > cursor is over object

    action > destroy the object

  • It doesn't seem to be doing anything. Forgive me if I didn't properly understand how to implement what you suggested, as I am rather new to this whole thing. My attempt is below:

  • About functions :

    https://www.scirra.com/manual/149/function

    About mouse object

    https://www.scirra.com/manual/114/mouse

    Add those objects to the project. Use them as i discribed.

  • Ah, you're a life saver. I did not realize that there was a function object. Thank you kindly.

  • Functions have 2 big advance.

    To minimize code lines.

    &

    To pick outside the piclkist made in the event with the call.

    The last reason is why i suggested the function. On dropped selects the object that is dropped. Not the object that it is dropped on. So, you can not reach that object until you make a new picklist. Now, the function always start to pick from scratch.

    Meaning, the mouse > cursor is over object .... will pick (and can pick) both objects.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Makes sense, and I've found it works with Touch as well.

    Out of curiosity, can you use the same Function in relation to different Objects without having to define the different Objects in a new Function?

    For instance, instead of having Function "S1L1" for Object Stg1Lv1 and Function "S1L2" for Object Stg1Lvl2, is there a way to make it so that Function "S1L1" works for both Objects?

  • You can call the function with parameters. Just add "S1L1" or "S1L2" as parameter. Have in mind that parameters (you can add many) are a list. All lists in C2 are zero based.

    Now, in the On function use two conditions

    System > Compared 2 values ...

    with ... function.param(0) = "S1L1"

    pick those with touch and do stuff on them

    System > Compared 2 values ...

    with ... function.param(0) = "S1L2"

    pick the others with touch

    Manual > Expression Param

    Retrieve a parameter passed to a function call by its zero-based index. For example, Function.Param(0) returns the value of the first parameter.

    You know wich one is dragged when you give them an instance variable, say, lets name it Level. Give it the value "S1L1" or "S1L2" in the layout.

    This way you can call the function with as parameter ... Object.Level (no if/thens, straight & easy)

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