How do I tell which instances share a container in a layout?

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 have a card sprite and a symbol sprite in a container and pinned together. And I have several instances of these card/symbol pairings on the layout. When I click one, it's set to rotate.

    The trouble is, I can't get the cards and symbols paired up. When I click one card, the symbol on a different card rotates. But when I swap them out so that the symbol that rotated is now over that card and try again, yet another symbol rotates instead. I've tried several times, but how it pairs them together in the containers seems to keep moving around.

    I know I could arrange the sprites in code at startup, but I find that hard to work with. I prefer the visual approach of using the layout.

    How do I determine which instances in a layout are going to get assigned to the same container?

    Thanks!

  • Have you tried putting each card sprite + symbol in a different family?

    More about families here:

    https://www.scirra.com/manual/142/families

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you tried putting each card sprite + symbol in a different family?

    Thanks for the suggestion. However, in this case there are only two sprite objects in total: a card sprite and a symbol sprite. All instances are of those two objects. As I understand it, families group different objects of the same type, not different instances of the same objects. Containers do group instances of the same objects, but I'm having trouble sorting out exactly how.

  • Containers only work if the objects are created dynamically. If that isn't preferable, you could use an ID. To simplify, put both objects in a Family, and give the family an instance variable: PairID. In the layout, set the ID of each to match the pair. On startup, foreach card, pick the symbol with the same ID, and use Pin to pin them together.

  • Containers only work if the objects are created dynamically.

    Ah, that's unfortunate. But thank you.

    I did find a sort-of work around. If I only place one of the instances in the container on the layout, then everything else will spawn and behave as intended. That doesn't allow a full visual design in the layout, but if I use the largest sprite in the container it makes for a pretty good sense of the final look.

  • Just a thought, for visual design-- you could use a placeholder sprite for visual design (it might look the same as the exact one) and you can even have it have some interesting attributes for the creation of the actual object.

    Then on layout start, you iterate through the objects in your designed layout and spawn a new object (with its container) at the same location, and destroy the placeholder.

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