How do I draw a line between matching adjacent objects?

0 favourites
  • 11 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hi guys. Super new to construct 2.

    Had a question on touch controls and conditions.

    Right now I have a bunch of "Dot" objects Laid out on a grid.

    The distance between each dot is about 160 pixels, and there are 5 different possible Dot colors (Same object, different animation frame).

    When a Dot is touched, a line of the same color spawns at the Dot's position, and its width adjusts to the position of the cursor.

    I want to make it so that when you drag the line to an adjacent Dot (Within 160px) of the same color, the current line stays in place and a new line starts.

    I roughly followed This video: youtube.com/watch to do the line mechanic.

    I have a global variable keeping track of the number of active (selected) dots.

    I have two different On touched events:

    One for when the first dot is selected:

    And another for when more than one dot has been selected:

    Under my assumption, whenever a Dot is touched, the system will pick the appropriate touch event depending on the NumActiveDots condition.

    However this doesn't seem to be the case.

    I managed to start the first line when clicking the first dot, but after that no other lines spawn.

    Sorry if I explained things in a complicated way.

    EDIT: Here's the capx: dropbox.com/s/u0ev0icxdmcvu2w/Dots.capx

  • So what you're saying is you copied the events in that video but it's not working? Share a screenshot of all of the relevant events, or the capx file itself.

  • I essentially did what the video said, but since the concept of what I'm trying to make is a bit different, I had to adjust it to fit my needs.

    Here is the event sheet as it is right now:

  • Have you tried running your project in Debug Mode (Ctrl-F4)?

    You'll be able to see what's going on - if the Line sprite gets created, which animation/frame playing and so on.

    If this doesn't help, try adding debug output. This could be a text objects somewhere on your layout. Make it big, set text wrapping=Character. Use Text->Append text to print some debug information to it. For example:

    MyDebug -> Append-> "ActiveDots:" & NumActiveDots

    or

    MyDebug -> Append-> "Line:" & Line.UID & " picked:" & Line.PickedCount

    Or you can use Browser->Log action for this.

  • Have you tried running your project in Debug Mode (Ctrl-F4)?

    You'll be able to see what's going on - if the Line sprite gets created, which animation/frame playing and so on.

    If this doesn't help, try adding debug output. This could be a text objects somewhere on your layout. Make it big, set text wrapping=Character. Use Text->Append text to print some debug information to it. For example:

    MyDebug -> Append-> "ActiveDots:" & NumActiveDots

    or

    MyDebug -> Append-> "Line:" & Line.UID & " picked:" & Line.PickedCount

    Or you can use Browser->Log action for this.

    Yeah, I probably should have mentioned, I added a debug statement to the second touch event, and it triggered on the first click of a Dot.

    Maybe it's instantaneously registering two touches?

  • Could you share your capx? It would be much easier to find the problem.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sure thing. Here it is:

    dropbox.com/s/u0ev0icxdmcvu2w/Dots.capx

  • In your event #5 the system picks 1 dot (which is clicked). Inside this event you can't pick other dots.

    If you need to pick another dot, you should do it either in a function, or add event "System->Pick all dots" and nest your events #8 and #9 inside it.

    There are other errors in your game, but at least if you fix this your second line gets created.

  • There is also a trick if you need to pick 2 dot instances and work with them independently in one event.

    Create a family and add your dot sprite to it.

    This will allow you to do things like this:

    On touched dot   <-this will pick one instance of dot
        Pick familyDot where <some criteria>   <-this will pick another instance of dot
        Line set width to distance(dot.x, dot.y, familyDot.x, familyDot.y)  <- draw line between two instances
    [/code:3o3pzqqj]
  • Thanks. Unfortunately I only have the free version so I can't use families.

    But I will use your previous advice

  • Scrap my previous advice

    Replace your whole event with this:

    You probably don't need the array. Just set some instance variable on the dots that are already connected.

    And one last thing - StartLine function requires three parameters and you only passing two.

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