Container without Pin behavior (?)

Discussion and feedback on Construct 2

Post » Fri Mar 08, 2013 4:28 am

I've read https://www.scirra.com/manual/150/containers and it gives an example about tanks and turrets, but in fact it doesn't have the expected behavior because if I create a tank I want the turrent to move along with the tank and that does not happens. Am I wrong? I'm using containers for something similar and, when I create the father object (the tank), the child (the turret) is created too but it stays in its place when the father moves.

If containers works that way, it would be great if the child would move with the father. I think it can be solved with the option "Automatically pin to father when created". I guess this isn't possible right now due to de imposibility to access to the father's son with triggers, events, actions, etc.

Thank you all! :)
B
29
S
6
G
5
Posts: 148
Reputation: 5,084

Post » Fri Mar 08, 2013 5:02 am

Containers are used for picking objects together, you still need to give both objects the action.

This is useful for when you have conditions that trigger on one or the other, and you want your set of actions to affect only those specific instances that are grouped together in a container.

For example, if you had an "on collision" type condition with the tank base object, and you had the action make tank turet flash, under normal construct logic all tank turrets on the screen would flash, because no specific instances were picked by the condition. If you had the two in the same container, then the tank turret associated with that tank base would be picked, and the action would apply only to that turret.

You should still utilize the pin behavior for the effect you are looking for.
Mistakes were made.
B
37
S
17
G
67
Posts: 1,041
Reputation: 38,211

Post » Fri Mar 08, 2013 9:26 am

Actually I agree with the OP how it should work. Containers shold work like along the lines of a parent -> child model. However it doesn't.

Container is a collection of objects(that can't share in other containers :( ) that are related to each other. Theoritically when one object in the container get's triggered for use. All the objects in the same version should. however that doesn't seem to happen all that often either.

For now. Just continue to use PIN. Not the best, but it at least works. C2 does many things great, but it's lack of a Parent/Child and it's simple PIN behaviour are it's weakest points so far :(

Otherwise fantastic tool :)
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Fri Mar 08, 2013 2:18 pm

It's intended that you use the Pin behavior. This means you can have it both ways (either have container objects that move along together, or objects that move freely and independently).
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Fri Mar 08, 2013 6:23 pm

But how can I use Pin Behavior if I can't pick the child (turret) when the tank is created?
I need to access to the child element with events, actions, etc. but after the tank was created...GamerGon2013-03-08 18:24:56
B
29
S
6
G
5
Posts: 148
Reputation: 5,084

Post » Fri Mar 08, 2013 7:03 pm

You can pick the child. The way containers work, if one object in the container is picked, then all other objects in the container are picked. So "Spawn base" followed by "Pin turret to base" should work fine.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Fri Mar 08, 2013 9:03 pm

When the base is created, a turret is created as well. Since they are in a container, referencing the turret right after making the base references the specific turret that base spawned with as containers spawn all parts when only one part is created.

Another way is doing it On Created of either the Base or the Turret, and pin the turret to the base as it will reference that specific turret and that specific base. This way allows you to have multiple things create the base without having you to add "pin turret" to all the actions that spawn a tank.Thndr2013-03-08 21:04:07
B
15
S
4
G
4
Posts: 294
Reputation: 3,225

Post » Sat Mar 09, 2013 7:56 pm

Yiey!
It works.

Another question related:
Is there a way to pick the father if the child triggers some event? for example, sprite B who is the child of sprite C is overlapping sprite X. I need to do something with the sprite C but I don't know how to get to it from its child.

Thank you guys.GamerGon2013-03-09 20:03:07
B
29
S
6
G
5
Posts: 148
Reputation: 5,084

Post » Sat Mar 09, 2013 9:15 pm

Right now I'm doing it with a common instance variable/value for sprite B and C, so I can match father & child but I think it is not the best way...
B
29
S
6
G
5
Posts: 148
Reputation: 5,084

Post » Sat Mar 09, 2013 10:01 pm

That is the whole point of containers, sprite b and c are always automatically picked together. If sprite B triggers an event, just do an action with sprite C and only the correct sprite c that is linked to sprite B will be affected.
Mistakes were made.
B
37
S
17
G
67
Posts: 1,041
Reputation: 38,211

Next

Return to Construct 2 General

Who is online

Users browsing this forum: NetOne and 2 guests