Object as a child of another?

0 favourites
  • 6 posts
From the Asset Store
Add emotion, innocence, joy and cuteness to your video game with these 15 songs and 9 SFX
  • I don't think this is currently possible, if it is I'd love to know how, but if not I'd like to suggest it.

    Currently I can only assign text, a boolean or an integer to an object. Could it be an option that we can assign other objects to an object in a similar way?

    I think it would be easier to say have an array attached to a sprite which could hold inventory data or something like that, than to have a global array. Sure the global array method works if you've only got one player, but using such a method in conjunction with say the multiplayer object can start to make the array a bit more confusing, especially for beginners. If the array could be set as a child of the sprite and each sprite had their own array, referenced like a behaviour can be would make construct easier to work with in my opinion.

    Another use could be to have a sprite as a child of another sprite which could function like a container, where if the parent is destroyed all children are subsequently destroyed, but if a child is destroyed its parents and sisters are not destroyed. Again, I think this extra aspect could make construct a lot more intuitive than it currently is.

    ~ Briggs

  • You could have the uid of the object inside said variable maybe?

  • You could have the uid of the object inside said variable maybe?

    But then if I wanted multiple objects? I would need multiple variables or use a cdl of the uids in a string variable; which would then need to be iterated over every time I wanted to use a child object. I know it works that way, it's just not as tidy than I feel it could be.

  • You can already pair an array with an object by using containers. You can do more elaborate stuff by using uid's. For example your second example could be done like so:

    on body created

    --- create head

    --- set body.head to head.uid

    --- create arm

    --- set body.arm to arm.uid

    on body destroyed

    --- pick head by uid body.head

    ------ destroy head

    --- pick arm by uid body.arm

    ------ destroy arm

    And you just use the pick by uid condition whenever you want to reference the child objects.

    Edit:

    In another way if you want a parent to have any number of children then you give the children a parent uid in the child instead.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [...]

    Edit:

    In another way if you want a parent to have any number of children then you give the children a parent uid in the child instead.

    But say the parent was destroyed, wouldn't you have to loop all objects that could be children to check that the destroyed object was their parent.

    I can see that it's possible with the tool-set provided, but I still think it could really help workflow. Coming from working with OOPLs I feel like this would aid the developer.

  • I too wish that C2 took a more OOP approach, but it's not likely to happen due to C2's architecture. Perhaps C3 will, but I doubt it considering Construct's target audience, and the fact that C2 projects will work in C3.

    Fortunately in this scenario, the workaround in C2 isn't onerous. If you add all objects to a family, add a "Parent UID" instance variable, and use it to populate each object's parent, you can destroy all children with just 2 events:

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