Atach a object to another

0 favourites
  • 7 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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.

  • type x instance variable= n

    -type y instance variable= n

  • 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..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can't you just match them with instance variables? Might be annoying, but until families are implemented, things like these are gonna come up.

  • 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...

  • 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

  • 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

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