Iterate Through Containers?

0 favourites
  • 6 posts
From the Asset Store
A well commented Dynamic Heart Containers template to learn from or to use as a base for your own game!
  • I need to pin several family objects together within containers, so the contained objects can be positioned as a group. How can I iterate across all the containers in a layout and reference the objects contained in each?

    It doesn't appear that I can use IIDs as the contained objects are from families and matching IIDs appear in separate containers.

    Thanks for any suggestions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not sure I understand the question. Do you have multiple instances of the same objects, grouped in containers? Then you can simply use "For each" loop for one object in the container, and instances of other objects will be picked automatically.

    For example, if you have a container with Car+FrontWheel+RearWheel sprites, you can do "For each Car -> FrontWheel Pin to Car, RearWheel Pin to Car".

  • Thanks for the response. To explain more, I have a dozen containers that each contain 2 objects -- they're essentially stretchable arrows with a shaft and an arrowhead. Multiple instances of these containers appear throughout the layout, and I can't figure out how to iterate through the containers to pin each set of contained objects. AFAICT I can't simply reference an object type or name because multiple instances of those objects exist in the layout.

    The way I see it, I need to somehow determine that an object lives in a container and then pin it to its corresponding object in the same container.

    Or is there another way to approach this?

    EDIT: Adding a link to an example layout:

    dropbox.com/s/21aolu9os7jttxm/arrow_test.c3p

  • As far as I know it's not possible to access other members in the container if you refer to them via family.

    Consider combining all these sprites into one. So instead of 12 separate Body sprites use one sprite with 12 animations. They will be much easier to work with and you will be able to use containers.

    With separate objects like you have now, it's almost pointless to combine them into containers. If you need to have separate objects, then I would suggest grouping them using hierarchy (scene graph). Hierarchy is compatible with families, so you will be able to do things like "For Each ArrowbodyFamily Pick Child ArrowheadFamily"

  • Thanks again for your suggestions on this.

    I would happy to use regular sprites, but the arrows are skewed to isometric angles and need to resizable, set to any random size in the layout, which is why the arrow bodies are made using 9-patch and tiled background objects (the arrowheads need to stay at fixed dimensions). AFAIK, there's no way to stretch a sprite (besides a simple line) along one axis without distorting it, is there?

    The use of containers makes it easier to treat each arrow as a single object in the layout. Sure, I could manage all the resizing/aligning behavior in code at runtime, but that means I'd have to build an entire editing system that saves and reads in all the arrow/object sizes and positions from external files, a fairly non-trivial amount of work.

    Anyway, I was also looking at using scene graphs as an option, so I guess I'll give that a try.

    Thanks again.

  • A quick update to this thread...

    Currently, creating the arrows as hierarchies seems to work well. They can be positioned in layout view as single objects (same as containers set to "select all"), they can be resized while maintaining their isometric perspective, and they can be moved as single objects at runtime without any laborious pinning required.

    So far so good, hoping I don't run into any additional issues. 🤞

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