How do I implement drag/drop?

Get help using Construct 2

Post » Fri Jun 27, 2014 10:15 pm

I'm new to Construct 2, I'm trying to implement a fairly simple drag and drop. On the left of the screen, there are 8 text sprites. On the right of the screen is a product label - the user must drag the correct text sprites to the correct position on the product label. If they release the text sprite in the wrong position, it should snap back to the left of the screen. If its in the correct position, it should get them positive feedback.

I have the text sprite loaded and draggable. but I don't know how to evaluate a condition when the mouse is released. I am planning to put a full screen sprite on the lowest layer - if the text label is dropped there it should snap back to the left of the screen. On one layer above that I'll put 'target' sprites for each of the text labels, and if they are 'overlapping' when the mouse is released I would like to set the text X/Y to position it properly on the label.

At this point I'm stuck on evaluating whether the user has dropped the text label over the correct sprite. Can anyone tell me what I should be using to evaluate that condition? I'm thinking something like this: "IF textLabel1 is overlapping TextLabel1Target THEN "good work!" ELSE snap it back to the labels start position"

Any tips appreciated. Thanks
Ronm
B
5
S
1
Posts: 28
Reputation: 327

Post » Fri Jun 27, 2014 10:42 pm

Quick and basic example.

There are 2 ways of doing it in the example checking if the "animation frame" is equal - Toggled disabled.

Or by checking if the 2 local variables are equal.

dragdrop.capx
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Mon Jun 30, 2014 10:06 pm

Hello Minor:
:D
Thanks very much for that file! I've learned a lot from it, still need to dissect it a bit more.

A few more questions if you don't mind. I need to have the user drag about 8 text labels to 'hot spots'. Is it better to create 8 text sprites and 8 hotspot sprites, or would it make sense to do what you have done and create one sprite in the editor that contains 8 frames, and put a different text label on each?

Also when the tag is properly dropped the text feedback that is given - is there some way I can randomize that feedback... ie 'good', 'right', 'correct', etc? Is there any way to use a list or array in C2?

Thanks again
RonM :D
B
5
S
1
Posts: 28
Reputation: 327

Post » Mon Jun 30, 2014 10:32 pm

With only 8 text sprites & 8 hotspot sprites either way would be fine and wouldn't impact performance or complicate matters. If you do use 8 of each you could use something like.

On drop sprite 1 overlapping hotspot 1 to see if it's in the correct place.

For random feedback I would use one of my favourite Construct expressions - choose. You could then use

Set text - choose("Well done","Good Job","Excellent work") Construct will then randomly choose one of the comma separated values and you can add as many as you like.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Post » Tue Jul 01, 2014 4:33 pm

'Choose' - hmm... haven't heard of that.... thanks I will try that.
B
5
S
1
Posts: 28
Reputation: 327

Post » Tue Jul 01, 2014 4:59 pm

Message: ronm is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
BTW Minor - is there some way I can contact you privately? I don't have enough 'points' to do so via the forum, my email is
B
5
S
1
Posts: 28
Reputation: 327

Post » Tue Jul 01, 2014 6:36 pm

OH OH I see I cannot post URL's or email addresses, OK for now.

Stuck again... things going smoothly to this point.... I've create a sprite that has 7 animation frames. Following the previously sent example closely, I'm loading 7 instances of this sprite (really text labels) with each set to start at a different 'initial frame'. Each has a different 'start_x' and 'start_y' value. The text labels are loading properly into different positions on the screen, but after the last one loads all of them are changing to the last one - so I have seven identical labels on the screen. I don't know if the 'initial frame' for each is being changed to the 7th or if something else is going on. I've matched the settings almost identically to the demo you sent me and really don't see any difference... but obviously I'm missing something important here.
B
5
S
1
Posts: 28
Reputation: 327

Post » Tue Jul 08, 2014 5:07 pm

did you set the animation speed to 0?
Image
B
71
S
28
G
12
Posts: 515
Reputation: 12,284


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests