Canvas Lines from Parent Objects to Child Objects.

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I want to have multiple sets of Objects that are connected with PIN. The first Object spawns on the layout.

    (Been using Canvas lines , Every tick)

    The part is selected with "Selected_Part_UID" to track what object is selected.

    Then when pressing the on screen button called 'ADD NEW'

    A new 2nd Object spawns a bit away from the 1st Object. The objects are in a family called Family_A. It has Family variables that will set the Temp Child or Parent UID of that Object. I need it so each part can have multiple child.

    The parts can be moved around with Mouse drag if the are 'selected'.

    Ok so I hope that explains what im asking.

    When the Button Show Parent lines is clicked it should show the lines.

    Ive tried many things now and each thing had failed. Asking Ai sent me in a loop of wrong things..

    Figured its not something that hasnt been done before so asking for help now hoping somebody already has a project already made.

    A object will have many child attached to it and you press a button to toggle the lines showing. thats all.

    Tagged:

  • So the drawing of the lines between the children and parents is what you’re having issues with?

    Sounds as simple as looping over each object and if it has a parent, draw a line between the two object positions.

    Or are you having issues of a different part of it?

  • So im about to go to bed but wanted to try and upload this test project. Ill add more to it tomorrow if no one else does.

    This is a test file of my real game just for this subject.

    So I know how to get lines to go from the one to the other objects but i have issues in my real game. Ill add more to this one to get it more like my main game.

    Its late here and I have to stop I didn't know it was so late.

    I want the lines to go from the parent to the Children. The objects will be enemies later so they will be moving around.(need every tick I think)

    However I didnt get to the point where if you selected the new Object and then add more parts it should be children of that part that is a child of the first part etc.

    The lines would show when the Boolen is set for them to show.

    Multiple enemies would have this "linking" but be separate. so it needs to work with that.

    Yes it seemed simple in my main game it worked ok at first but then I seen issues as more things was going on. I have 2 objects like in this project that are in the same Family.

    https://file.kiwi/bdad2082#xh0jqzi9fLRfjq9s-ZgV_A,34e08fed

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could look into hierarchies, and just set the child/parent relationship with an action when you create child objects. Then drawing lines would be simple as looping over children, picking parent, and drawing lines. It supposedly would look like this:

    start of layout
    -- create pup at (100,100)
    -- adult: add child: pup
    
    every tick
    -- canvas: clear to rgb(0,0,0,0)
    
    for each pup
    pup: pick own parent adult
    -- canvas: draw line from (pup.x, pup.y) to (adult.x, adult.y)

    If you don't need the positioning that hierarchies provide you could use a "parent" variable on the child objects. Make the default value of that instance variable -1. That would look like this:

    start of layout
    -- create pup at (100,100)
    -- pup: set parent to adult.uid
    
    every tick
    -- canvas: clear to rgb(0,0,0,0)
    
    for each pup
    adult: pick by uid: pup.parent
    -- canvas: draw line from (pup.x, pup.y) to (adult.x, adult.y)

    Either way would be fine as long as the parent and child sprites were not the same type or family.

    If you wanted the parent and child to be the same type or family then it would be tricker. In general that type of thing is trickier with the picking system, but one strategy is to pick one, save values to variables, then pick the other.

    For example, if you had a family "dog" with types ("pup", and "adult"), and the family had an instance variable "parent" with a default value of -1.

    start of layout
    -- create pup at (100,100)
    -- pup: set parent to adult.uid
    
    every tick
    -- canvas: clear to rgb(0,0,0,0)
    
    var puid=-1
    var x=0
    var y=0
    
    for each dog
    -- set x to dog.x
    -- set y to dog.y
    -- set puid to dog.parent
    -- pick all dog
    -- pick dog by uid puid
    -- -- canvas: draw line from (x, y) to (dog.x, dog.y)

    Observe that the last event should have a sub-event starting with "pick all" (sub-events are harder to depict with text).

    Anyways, just some ideas.

  • Thankyou.

    Busy few days of the week but will work on it today and try what you said!

    That last part for sure. Yes it was something tricky. seems to work but I had issues with it picking objects on another layer even if I have it set (I thought) to not select that object on that layer.

    Anyways I feel like ill run into an issue later with it.

    UPDATE 7/2/2026:

    OK What you said seems to work correctly. I had this working already tho or close to that.

    The issue I have now is the line you have SET TO ADULT.UID.

    Like I was saying when you double click a pup then click the Add Puppies Button again the pup should also now have children and lines going to the pup to its puppies.

    The reason for the Main object being different is because it will be like the main object and if it gets destroyed then all the child will too and only the "adult" will be moving with the children pinned to it.

    The lesser objects(Puppies also need to have children) and so on. So the Adult.UID only works for the first one.

    It wont be a dog in the game but many parts that connect to the main part(adult) but then split into more from child to child.

    Im going to mess with it more today but if you know the best way to deal with that let me know please!

    Thanks

    Here is updated project:

    file.kiwi/0d0aca63

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