How do I create drag and drop functions for match game

0 favourites
  • 4 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • Hi there

    Can anyone help me to create an educational game where I want to have the numbers 1,2 and 3 and an image of the number 3 elsewhere on the screen. he user then has to use the mouse/touch to drag the correct number inside the picture and if correct it should play a sound or create a new image.

    I've tried looking for videos and tutorials but can't find anything or perhaps I'm not using the proper search terms. Still very new to programming and Construct 2. Thank you in advance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct 2 has a behavior called "Drag and Drop" which makes the object that has the property able to be dragged and dropped where ever you want. Simply start a new project, place an object on the visible area, give it the "Drag and Drop" behavior and hit run. You will be able to move the object around as desired. All that is left is to test if the location the object is set is correct or not. To make it return to it's previous location on failure, give the object local variables containing the x and y positions of it's start position and on failure, set the objects x and y = to the stored x and y.

    There is a tutorial RPG-Inventory drag and drop. you can find it here:

    https://www.scirra.com/tutorials/244/rp ... g-and-drop

    It shows a more extensive answer to your question. I have not actually read through the tutorial but it appears to go over a little more than what I did.

    There is a large collection of tutorials on this site to help people just getting started. To find the above tutorial, you could go to the Tutorials section and in the search box, type "drag and drop." I'm not sure how/where you looked for tutorials but this is how I found the tutorial reference for you.

    Also, Construct has quite a few examples shipped with it. In many instances, you can find one which will show you how to use most of the functionality by creating a new project and scrolling through the list of templates.

  • Hi Frag

    Thank you for the quick response. I wish there was a step by step guide I'll try and figure out how certain parts work because like I said I'm a total beginner and just missing one step if not showed clearly, throws me off. I'll keep working at it. Thank you for the help, I appreciate it.

  • I wish there was a step by step guide

    Unfortunately, for most things there won't be a step by step guide. However, to help you get started, I am attaching an example file showing exactly what I wrote in my previous post. It uses a single main event with 2 sub events. I tried to make it as basic as possible so you should be able to look at it and get what you need from it. The blue square has the drag and drop behavior. The event simply states, when the blue square is dropped, check its location against the black square location. If the blue square is on top of the black square, it snaps to the black squares location and get disabled so it cannot move anymore. If it is dropped anywhere else, it returns to the middle of the screen. That is it.

    I hope this will help.

    <edit> I noticed a bug in my capx file. A new version with the fix has been uploaded.

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