How do I - Drag and Drop Problems

Get help using Construct 2

Post » Sun Jun 19, 2016 2:52 pm

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:

Image

Any and all help would be appreciated.
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Sun Jun 19, 2016 3:23 pm

condition > On drop
action > call function

condtion > on function
sub > cursor is over object
action > destroy the object
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jun 20, 2016 1:23 am

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:

Image
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Mon Jun 20, 2016 12:15 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jun 20, 2016 2:03 pm

Ah, you're a life saver. I did not realize that there was a function object. Thank you kindly.
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Mon Jun 20, 2016 3:58 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Jun 20, 2016 4:49 pm

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?
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Mon Jun 20, 2016 6:42 pm

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)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, gskunk, richcoz81, tarek2 and 40 guests