How do I implement drag/drop?

0 favourites
  • 8 posts
From the Asset Store
Use inertion of your movements to throw, rotate your objects and etc. Objects can interact with others while dragging.g
  • 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


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.


  • Hello Minor:

    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


  • 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.

  • 'Choose' - hmm... haven't heard of that.... thanks I will try that.

  • 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

  • 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.

  • did you set the animation speed to 0?

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