How do I access an objects parent?

0 favourites
  • 10 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • I have a parent sprite that adds a particle child with the scene graph. As I cant seem to inherit the parents z index by default using the scene graph i need to do it manually, but there doesn't seem to be a way I can access an objects parent anywhere.

    For example: I want to tell the particle to be on the same layer as its parent.

    Any way to do this?

  • Have you tried "Pick parent" condition?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I tried this but I have no idea how its used. Once I have picked the parent how do I access that object to tell it which zindex to be on. I tried a few things but nothing seems to work. I cant find any example usage.

    For example, I tried this but it doesnt work:

    + Particles: Pick Own parent Rock

    -> Particles: Set Z elevation to Rock.ZElevation

    I would have expected once the parent is picked to be able to do something like:

    + Particles: Pick Own parent Rock

    -> Particles: Set Z elevation to PickedParent.ZElevation

    But of course that command doesn't seem to actually exist. :)

  • It does work exactly as you said it should. Make sure that when you add the particles to the parent you are not asking it to replicate the parent's Z-Elevation

  • z-index is not the same thing as z-elevation. If you want to move particles to the parent Rock object on z-axis, you should use "Move to Object" action. For example:

    Particles Pick Parent Rock
     Particles Move to layer Rock.LayerNumber
     Particles Move in front of Rock
    
  • It does work exactly as you said it should. Make sure that when you add the particles to the parent you are not asking it to replicate the parent's Z-Elevation

    When creating the rock I am simply doing:

    -> System: Create object Particles on layer 0 at (Rock.X, Rock.Y)

    -> Rock: Add child Particles (X: True, Y: True, width: True, height: True, angle: True, destroy with parent: False)

    is that wrong?

  • Firstly can you clarify if you are looking to change the Z-elevation, or the Z index? As dop2000 said they are different things. If you are looking to create the particles at the rock coordinates, and there is only one rock, and then have the particles always be the same Z-elevation as the rock sprite, then you can use:

    On whatever condition then

    action -> Create object 'particles' Rock.x,Rock.y

    action -> Add child 'particles' to Rock (and make sure the Z-Elevation option is selected)

    action -> Set 'particles' Z-Elevation to Rock.Zelevation

    This will always match the particles Z-elevation to the rocks.

    If you only want to match the Z-elevation at time of creation and not have the particles z-elev transform to that of the rock later then you can uncheck the Z-elevation box when adding the child.

    If you have multiple rocks, you will need to use a pick condition that chooses the correct rock.

    demo here: 1drv.ms/u/s!AkmrWgxeuxlKhIcnLZBM7z8smX04dg

    If you're looking to move the particles to the same layer as the the parent then do what dop2000 suggested. Or if you know the layer that the rock is on then set it correctly in the create object action.

  • OKay, but I cant see any z-elevation option when adding the child, only x,y, width,height,angle and Destroy with Parent. I am using 218 stable. Maybe that's a new feature?

  • Ah yes it may be, I can't remember when it was added. If you want to switch to the beta you'll have access. Elsewise you could ignore the hierarchy and add another event that picks the two objects and use every tick set childobjects Z-elevation to parentobjects Z-elevation.

  • Okay. Thanks everyone for all the info. Much appreciated.

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