Page 1 of 1

Parent,child & Z-buffer

PostPosted: Sat Jan 16, 2010 9:16 pm
by Leif
Hi :)
Tell, plz, what to do with :

We got two Actors - A and B. We need to generate every turn several actors A and equal quantity of B under them ( it's like unit A and it's shadow B in pseudo-isometric strategy). Initially we set z-depth of A higher than B. But if we do " Create A, on create A create B (pick event A as a parent) " several times, we get "the first B covers next A". Trying to change z-depths after that does not help.

How to make it right ? :)

Re: Parent,child & Z-buffer

PostPosted: Sat Jan 16, 2010 10:26 pm
by DST
Children inherit attributes from their parents. There is no way(that i know of) to have a child below its parent. A child actor has its x+its parent's x, its z + its parent's z.

The idea is this: You make buttons a child of their menu background, you make lights a child of the car they're attached to, or you make an actor a child of it's playfield (the goldenT game engine uses this background method).


Do away with the parenting, and instead on B> Draw Actor>
x=creator.x;
y=creator.y;

Re: Parent,child & Z-buffer

PostPosted: Sat Jan 16, 2010 11:01 pm
by Leif
Thanks :)
But it does not work when I'm dragging parent A.

By the way, is there a simple method to destroy B simultaneously wiyh A ? And change animations simultaneously ?

Re: Parent,child & Z-buffer

PostPosted: Sun Jan 17, 2010 1:00 am
by DST
Simply ask for a variable from A, like so: (create an actor variable called 'alive')

A>CreateActor>
Code: Select all
alive=1;


B>Draw Actor>
Code: Select all
animpos=creator.animpos;          //give them the same animpos
x=creator.x+100;
y=creator.y;
if(creator.alive==1){                      //check only that A is alive
}
else{DestroyActor("Event Actor");  //a dead A cannot return an alive of 1, therefore B dies.
}


See if that works for you. If you need to use animation changes, you can get creator.animindex to see which animation A is on.

As far as the problem with dragging, i don't know what's causing that. In my test, b followed a perfectly, both using creator.x and this->x methods.

I assume you are using A>mousebuttondown>drag:enable> ? And also, A is no longer a parent of B, this method makes the parenting obsolete.



If you want to get more information from the creator actor, you can use *Actor.

Its a bit more complicated, and probably slower, but so it goes. Note that B can get any attribute of A this way; and also can modify A if it needs to. *Actor is a complete I/O method between the two actors, always using this->variable instead of this.variable.

1st, create 2 actor int variables, pid and alive.

B>CreateActor>
Code: Select all
pid=creator.cloneindex;

A>CreateActor>
Code: Select all
alive=1;


Then use the getclone2 script

B>Draw Actor>
Code: Select all
Actor *this=getclone2("A", pid);        //stores its creator "A" as "this"
x=this->x+100;
y=this->y;
if(this->alive==1){}                                    //check only that A is alive
else{
DestroyActor("Event Actor");                      //a non-existent a will return an alive of 0
}


Notice how in B's draw actor i used an if/else. A must exist in order to return a successful "alive" to B; if A dies, this->alive cannot equal 1 therefor B dies.


Here's the getclone2, in case you don't already have it: (paste it into global script)
Code: Select all
Actor *getclone2 ( char *actorName, long cloneNumber )
{

  char resultString[256] = "";
  char cloneNumberAsString[10];
  Actor *resultActor;

  strcpy ( resultString, actorName );
  strncat ( resultString, ".", 1 );
  sprintf (cloneNumberAsString, "%i", cloneNumber);
  strncat  ( resultString, cloneNumberAsString, 10 );

  resultActor = getclone(resultString);

  return resultActor;

}





Note too that you could run all of this script from actor A, but it requires an extra step as you have to find a way to get B's cloneindex and feed it into A, so it's probably simpler to do it from B.