How do I create a simulator without predefined positions?

0 favourites
  • 12 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I need to create a circuit assembly simulator. The assembly area must be without predefined places, that is, the users can mount it wherever they want and I have to identify if he made the correct connections as shown in the diagram. I thought about using something that would check the overlap of image points, I don't know if it would be the best, but I still don't know how to do to identify if each part is connected correctly and I need help with that. I am creating a template before and shared it here. There is also the diagram to look at as a reference (it cannot be under the assembly area for the user to place the parts on top, it is just a reference).

  • Please, some help here. if you don't want to edit the file, feel free to only suggest your ideas. I would like to understand what are the possibilities I have to achieve this goal. Thanks

  • Well the first part would be to somehow keep track of what is connected to what.

    One way would be to have the nodes you drag around, and the connections could be indicated by line sprites with two variables that indicate the two uids of the connected nodes.

    Since these are electronic components, I'd suppose each component has two nodes, an in and an out if you will.

    So you'd have components you can drag around, each with two nodes. Then you'd have a way to add a wire between any two nodes. It's doable by referencing stuff by uids, but there are probably other ways.

    To tell if a connection setup matches another should mostly be a matter of checking if the same list of components are used, and they have the same connections. I need to mess with the idea more since there is the issue with the order you added the components. Also most components with maybe the exception of batteries can be connected in reverse. So it would amount to checking all the different combinations.

    You could probably do it easier by checking some other criteria to see if it's a correct setup. Maybe just the same components used and everything is powered. Things like limiting the configurations possible can simplify things too, such as a single loop circuit.

    That leads to how the power is transmitted. For a single battery a simple thought would be to start from the positive and do a astar search along the connected nodes to the negative. For a true simulation it's probably more nuanced dealing with resistance. Probably a flood fill along the connections would work. Flood till you make a circuit. Electricity physics would be your friend here for really good results.

    Anyways, here's a example of how uids could be used to keep track of the connections. It also shows how a basic flood fill can be done. Could be useful for some ideas.

  • Thank you very much for helping me with this project. You have helped me many times over the years.

    I looked at your capx and I think it took away some doubts about how I could do it, such as including nodes at the ends of the components, for example.

    In the case of the battery, it should also have two nodes (but in this case the position will not be at the ends, but at the top, one on each pole of the battery) and also move around the screen like the other components.

    The wires will also have these characteristics, that is, they will be separate objects. Blackhornet suggested the use of TiledBackgrounds, and in this case, the nodes would be the same ones used to define the length of the wire. I do not know if it is possible to snap the nodes of the wires and the nodes of the components, but this would be great.

    I think the big problem will be to be able to identify each of the components (battery / resistor 100-ohms / resistor 200-ohms / fuse / switch) and to know if they are connected according to the diagram:

    1- A battery pole connected to the fuse,

    2- fuse connected to the switch

    3- switch connected to the 100-ohm resistor

    4- the 100-ohm resistor connected to the 200-ohm resistor

    5- 200-ohm resistor connected to the other pole of the battery, closing the circuit.

    How will I know if the 5 components that are connected by wires and following the correct order?

  • Nice Fun Puzzle to solve))

    How will I know if the 5 components are connected by wires and following the correct order?

    There a few questions still not very clear

    1-Can you solve in the same order but rotated



    2-Can the pieces be flipped?


    And The same for the battery:

    And the same for rest of the pieces


    3-Is The correct solution just about the order that is connected or Both (Order & Angle)


    The Switch from your picture is connected this way

    But what happens when they connected it in the right order but is rotated like this

    Is that a valid solution?

    The same for all the other pieces

  • Hi tarek2

    Logically, the user will be able to assemble following the order of the components, regardless of position, but if that can be a complicating factor, as he will see the diagram while assembling, I can ask him to assemble exactly the same structure.

    Components and wires cannot be flipped but can be rotated 90 degrees or -90 degrees, that is, they can rotate 90 degrees and return to the starting position.

    For example: the switch can only be in the vertical direction if it is placed on the sides of the circuit

  • Hi tarek2

    Logically, the user will be able to assemble following the order of the components, regardless of position, but if that can be a complicating factor, as he will see the diagram while assembling, I can ask him to assemble exactly the same structure.

    I see,

    Just to make sure, so you mean this is a valid solution right

    Components and wires cannot be flipped but can be rotated 90 degrees or -90 degrees, that is, they can rotate 90 degrees and return to the starting position.

    Yes, that's why I was asking as you can rotate them at some point it will be flipped, or at different Angles so is that matters or you just looking for the right order?


    Are this a valid solution even if they are connected in the right position & order?

  • These options that you included could be right, but if this is going to complicate the development of the project, I can leave the positions restricted to what is being shown in the diagram, that is, only one solution

    The components could be inverted, but I think this is a problem. I thought about just allowing them to rotate 90 degrees once and/or return to the initial position.

    Complementing, yes, the switch could be right if the user rotated it this way

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I see,

    I haven't tried yet but I think it looks like if you just follow the order of the objects of how it should be connected and don't bother about their Angles it will be the easiest like this. since you allowing Rotation.

    but not sure because I haven't tried it yet this is just a guess, it could be other things that can complicate the logic that it's not obvious at the first look, I guess is just about testing and see what is the easiest and the one that gives the fewer complications.

  • Yes, I think so. Even the actual components do not always have to be in a specific orientation. The only need is for the wires to be separate objects and not part of the components, that is, I will also have to position them in the same way I have to do with the components, as they appear in the diagram.

  • Here's the way i found to see if a circuit is connected in a particular way. The idea is you give the wires an id and per connection you specify the two wires connected on either side. It looks like this:


    Now, depending on how you connected the stuff together it could give you this instead


    They still represent the same configuration, and there can actually be 5! (5 factorial or 5*4*3*2*1 or 120) different combinations that are correct when there are 5 wires. So to see if they match we check them all.

    The good news is different wires connected to the same nodes are considered the same nodes so that reduces the complexity.

    Also in this example i made it not matter which way you hooked up the components. For most components, like resistors, it doesn't matter, although things like batteries probably do matter.

    This is the circuit you're trying to match.

  • R0J0hound

    I will take a look at the file. Thanks so much for all the explanations.

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