Atach a object to another

Discussion and feedback on Construct 2

Post » Sun Dec 11, 2011 8:01 pm

Hi! I have a lot of objets of type X and a lot of type Y.
Each object X determines the position of a child object Y. How can I create a father->child bond ? I dont want o use joints because its so slow.
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
21
S
5
G
6
Posts: 166
Reputation: 4,885

Post » Sun Dec 11, 2011 8:04 pm

type x instance variable= n
-type y instance variable= n
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sun Dec 11, 2011 10:06 pm

I dont know how to do this. See, I have a lot of objects pairs how to know bind theses pairs? I dont know how to get a individual instance of a type of object and I need this. I was thinking in store this relation on a instance variable and then loop in all objets of that type to see if that object is my "father" and get its x e y, but I dont know how..
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
21
S
5
G
6
Posts: 166
Reputation: 4,885

Post » Sun Dec 11, 2011 10:13 pm

Can't you just match them with instance variables? Might be annoying, but until families are implemented, things like these are gonna come up.
B
47
S
10
G
6
Posts: 455
Reputation: 8,326

Post » Sun Dec 11, 2011 10:27 pm

See, theses pairs are created at run time. In this moment Im trying to create a loop for each instance of object type A and in this object type A I have a index that represent the nth object B. But I dont know how to get the nth object B. The expression shuld be something like this:
for each OB in Object_Type_A do
{
   x = Object_Type_B[OB.index_reference].x
   y = Object_Type_B[OB.index_reference].y
}
Something like this...
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
21
S
5
G
6
Posts: 166
Reputation: 4,885

Post » Sun Dec 11, 2011 10:48 pm

You just wanna attached them to a parent object? If so, you could use the "Pin" behavior. When you create them at run time, you can set their instance variables to a certain number, and each number correspond to a parent object, and depending on the variable they will attach to their corresponding parent object. Say you have parent object "blue" and you create child objects "blue". Give the children the Pin behavior and create an instance variable, I will call it "relation". Set relation to 1 for example at the time you create the children and attach them to the parent. All "blue's" children should have the relation variable set to 1 at the time of creation.

I have never used the Pin behavior, but, it should do the job, I think. And quite possibly I haven't understood exactly what you are trying do. :P
B
47
S
10
G
6
Posts: 455
Reputation: 8,326

Post » Sun Dec 11, 2011 10:51 pm

You would use the object your actually controlling. If that object was type x, you would do the for each on the type y.

-+ for each type y set position to type x(loopindex).x, type x(loopindex).y

Without using the index you could assign a variable a value like:
-+system on start of layout
->for n =1 to 100
-->system create object type x
--->type x set variable to loopindex("n")
-->system create object type y
--->type y set variable to loopindex("n")

Then use the variable comparison, as I suggested before.
A loop, or a for each should be used here as well.

Btw type x, and type y... probably not the best naming method. :P
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests