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

Get help using Construct 2

Post » Fri Jul 04, 2014 5:36 pm

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!
B
8
S
2
Posts: 55
Reputation: 616

Post » Fri Jul 04, 2014 6:00 pm

Have you tried putting each card sprite + symbol in a different family?
More about families here:
https://www.scirra.com/manual/142/families
B
6
S
1
Posts: 73
Reputation: 571

Post » Fri Jul 04, 2014 6:06 pm

rezagamertag wrote: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.
B
8
S
2
Posts: 55
Reputation: 616

Post » Fri Jul 04, 2014 6:17 pm

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.
ImageImageImage
B
71
S
22
G
242
Posts: 3,734
Reputation: 134,994

Post » Fri Jul 04, 2014 7:10 pm

blackhornet wrote: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.
B
8
S
2
Posts: 55
Reputation: 616

Post » Wed Aug 13, 2014 2:14 pm

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.
B
5
Posts: 10
Reputation: 250


Return to How do I....?

Who is online

Users browsing this forum: dand, mageekm, oosyrag and 29 guests