Parenting and Zdepth - explained

Talk about making games.

Parenting and Zdepth - explained

Postby feral » Fri May 30, 2008 11:56 pm

guys, not sure if anyone has done this yet, but i recently had a need to parent actors, and discovered the issues with child actors receiving zdepth level relative to the parent..

I have had a play around and this is what I discovered.

1. zdepth appears to be only accurate to two decimal places.. eg: .998 and point 999 are equal (I could be wrong here)

2. a child will always receive a zdepth "higher" then the parent, (the child will always be on top of the parent)

3. two children on the same parent can be zdepthed to each other ( but not the parent)
(the child actors will always be on top of the parent, but can be layered individually amongst themselves.

4. the zdepth of individiual children has NO effect on any other actor, all other actors will use the parents zdepth,
(To all other actors the children will appear the same zdepth as the parent. )

example case

actor 1 is a character
actor 2 is the gun which is parented to actor 1
actor 3 is ammo which is parented to actor 1

ammo and gun can be separately zdepthed so that either the gun or the ammo are on top, BUT neither can be below the parent actor.

if the parent actors zdepth is .59 - the parent and ALL children will be below ANY other actor with a zdepth of .60 or above

and, the parent and ALL children will always be above any other actor with a zdepth of .58 or below - regardless of the individual settings of the child actors..

example: the character holding a gun and ammo ( parent and children) will always move "together", behind/ or in front of trees/buildings etc even if the childs zdepth is set to 1 or 0,

(only the parent zdepth counts.)

in other words..

always make the sprite you want to be at the back of the parenting structure the ONLY parent ( AND the one controlling the zdepth interection with the rest of the game) (see note), and make all other connected actors ( guns ammo etc) children of the same parent this way you can adjust the individual layers of the children.



I hope that makes sense and helps someone - and/or if there is a tutorial already on this please let me know

(and/or if i got it wrong)

note: when i say "always make the parent the ONLY parent".. i mean in general... (for example there may be times you want to parent another group of "already parented sprites" to an existing parent)

feral
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: Parenting and Zdepth - explained

Postby DST » Sat Jun 07, 2008 5:22 am

Great explanation! You are a natural with GE!

I would like to add that professional programmers do not use Child/Parent. They use xy coordinates. They link one actor to another, probably thru a variable.

xx=parent.x;
xy=parent.y;

x=xx;
x=xy;

or something like that.

Parent/child is for menus, puzzle game, RTS components. Use xy coordinates for action games.

Ge is here to make stuff easier, but it's not magical!
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest