Parent,child & Z-buffer

Game Editor comments and discussion.

Parent,child & Z-buffer

Postby Leif » Sat Jan 16, 2010 9:16 pm

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 ? :)
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Parent,child & Z-buffer

Postby DST » Sat Jan 16, 2010 10:26 pm

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;
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

Re: Parent,child & Z-buffer

Postby Leif » Sat Jan 16, 2010 11:01 pm

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 ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Parent,child & Z-buffer

Postby DST » Sun Jan 17, 2010 1:00 am

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.
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 GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron