Composite Object Families in Editor

0 favourites
  • 10 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hi all,

    How can "link" objects together?

    Let's say I have 5 different sprites in the editor (e.g. football, tennis ball, golf ball, ...) which share some behaviour and therefore are grouped in a family ("Balls").

    I also have 5 different "Indicator" sprites in the editor (with different sizes to fit the respective ball). Now I want to move the indicators with the balls and show/hide them.

    My problem is not the moving or showing/hiding part, but the fundamental logic how to link Indicator A to ball A, Indicator B to ball B and so on.

    I hope you can point me out some tipps?

    Any hints appreciated!

    Thx a lot

  • Pick one = pick the other :

    https://www.scirra.com/manual/150/containers

  • Thank you veeery much for pointing out containers 99Instances2Go.

    So I know how to create a container with e.g. "Football" which references "Football_Indicator". But how do I create a generic familiy which references another family?

    For my example: Family "Balls" references Family "Indicators".

    When I pick the object Football, I get the object Football_Indicator

    When I pick the object Golfball, I get the object Golfball_Indicator.

    When I pick the object Basketball, I get the object Basketball_Indicator.

    ... and so on for another 10000 types of balls

    How can I destroy/highlight or whatever (It's just about the picking) the respective indicator when I touch an object?

    Thanks again for helping me out - to finally understand the fundamentals of construct

    For now I have done a really messy workaround. This can't be the solution... I just post it here to make the problem even more clear:

    • I have created a family variable "REFERENCE" in family Balls, and a family variable "REFERENCE" in family Indicators.
    • I have manually written e.g. "FOOTBALL" into the REFERENCE field of the Ball and the Indicator object
    • Then, whenever a ball was clicked, I iterated over all Indicators and checked if the indicator REFERENCE matched the Ball REFERENCE.

    PS: I have also done a small test setup project, but it seems I cant paste URLs here..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I do not know how to make Familys play nice, friendly and useful with Containers. I did't catch that it is about family's.

    When family's are in play, i use an instance variables to pair objects.

    https://www.dropbox.com/s/o8ige6sf7goz2 ... .capx?dl=0

    But why not make it yourself a lot easier ? Talking extensively about 1000 "faces" now. Even assuming that they all have different properties like Jumpiness, that can be written in a .json (in a text editor, or a online json editor)

    https://www.dropbox.com/s/03eaewwuuxe2w ... .capx?dl=0

  • Thanks for your answer.

    By "use an instance variables to pair objects" you do the same as me, which I've stated as "messy workaround".

    I just bumped into the same problem again. I have 3 different buttons, each one with a shadow (separate object), and I want the shadow to disappear when the button is clicked -> There is no clean way to do this in Construct 2 afaik.

  • I do this all the time. Have one button object, with different frames, or animations, and a container. You just decode the object that was pressed to get the actual item.

    http://www.blackhornettechnologies.com/Construct2Stuff/Gordo1958_buttonsample.capx

  • If you are using Pin bahavior to physically link your objects one to another (indicator to ball), you can do this:

    On Ball clicked ->
      System -> Pick Indicator by evaluating Indicator.pin.PinnedUID=Ball.UID  
       // you get your pinned indicator
    
    On Indicator clicked ->
      Ball -> Pick by unique ID:  Indicator.pin.PinnedUID
       // you get your pinned ball
    [/code:2tagjru4]
    
    This works with families and I'm using this trick a lot in my game.
    
    Also, I don't understand what's wrong with instance variables? 
    In your example you use something like Reference="Football", this is ok if all your objects are created in editor. 
    If you are dynamically (in runtime) creating a new instance of Ball family and a new instance of Indicator family and you want them to be linked, just add an instance variable Indicator.BallUID. This is not a "messy solution", but a very common approach. And you'll not need to iterate through all objects to find a linked one, just do this:
    [code:2tagjru4]
    On Ball clicked ->
      Indicator -> compare instance variable Indicator.BallUID=Ball.UID  
       // you get your respective indicator
    
    On Indicator clicked ->
      Ball -> Pick by unique ID: Indicator.BallUID
       // you get your respective ball
    [/code:2tagjru4]
    
    [quote:2tagjru4] I have 3 different buttons, each one with a shadow (separate object), and I want the shadow to disappear when the button is clicked -> There is no clean way to do this in Construct 2 afaik. 
    
    You can do this easily even without creating any links between the button and its shadow.
    [code:2tagjru4]On Left button clicked on MyButton
      MyShadow pick nearest to MyButton.x, MyButton y     
       //  Set MyShadow Invisible or destroy
    [/code:2tagjru4]
  • blackhornet, Thanks for your reply. Your solution works for this specific case, but you are kinda "misusing" the animation system to get your result. What if you want to have the buttons and/or shadows animated?

    dop2000 Thanks for the really detailed reply! The pin behaviour solution looks like the logically cleanest solution for now, but what if I don't want to have the objects pinned physically together? The same goes for the "pick nearest" solution. May work for some cases, yes. But I just need a logical reference, not based on distance or whatever...

    Another example:

    I have the family "Balls"

    I have the family "Ball_Icons", which show every different kind of ball inside the GUI.

    If you click one "Ball" instance, the respective "Ball_Icon" should disappear.

    E.g. I click the Basketball, the basketball icon disappears.

    Sidenote: Every Ball is animated, Every Ball_Icon is animated, Icon and Ball should not physically pinned together, Positions and distances are random

    This sounds like a very specific thing, but the core problem is: Logically referencing two objects without big overhead. Of course there are plenty of hacks/ways to do it, but there most be a clean solution, since its one of the most crucial fundamentals of a gameengine. Maybe I don't get it right since I am a Construct 2 Newb

  • Gordo1958

    If I understand correctly you need to:

    1-When clicking any ball the icon linked to that ball has to hide

    2-Same for the buttons, when clicked button the shadow linked to that button, has to hide

    All of this Linking without using "Variables" or "Pin Behavior" not many options left

    Will be easier if you share the capx and all the steps and linking that you want and you don't wanna is hard to guess everything how has to link

    See if this can help you:

    Linking no pin, no Variables:

    Capx: the icons are flashing instead of hiding but you can change it to however you like

    https://www.dropbox.com/s/cpjd7voh4e58kq2/Link%20Buttons%20%26%20Icons%20No%20Variables.capx?dl=0

  • Gordo1958, use instance variables, it's a perfectly good solution.

    If you have many Basketball instances and 1 Basketball icon - create instance variable "type" on both families and set it to "basketball" for all Basketballs and Basketball icon.

    If you want each individual Basketball instance to be logically linked with its own Basketball icon - create variable "iconUID" on the Balls family and set it to icon.UID

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