Page 1 of 1

Parenting Problem

PostPosted: Fri Dec 25, 2009 7:11 am
by arcreamer
Hey guys I just got back and I'm still gettin adjusted again.. now I want my background and a shadow to follow my actor like a parent but when I parent them to the main player, their Z Depth gets messed up... any help would be appreciated :)

Re: Parenting Problem

PostPosted: Fri Dec 25, 2009 8:47 am
by skydereign
Well several ways to do it, though I try to avoid using parenting, as if you ever do any 2.5d games, it can really get in the way. One trick to do what you want is to make an actor, and make it invisible, but allow events. This actor should be lower zdepth than anything within the view, but you can parent everything that needs to follow the screen around to that. All actors parented to this new actor will have higher zdepth, but you can make them all relative to each other, so your shadow can be lower. Again, you might note some problems with this if you have a background that is not supposed to move with this actor.

Another way is to use an absolute placement from an actor. This actor would be the equivalent of the parent actor, as all actors that would be parented to it have some code similar to what I have below. Again this has its ups, but it isn't all that optimal.
Code: Select all
x=referenceActor.x+100;
y=referenceActor.y-50;


The last thing I'll suggest is to right an equivalent to a moveto function, that moves all the actors you want it to. So lets say if all of your actors you are supposed to follow an actor, player, than whenever player moves you would use the function. The following is what it might look like in global code.
Code: Select all
void
MoveActors (int xspeed, int yspeed)
{
    player.x+=xspeed;
    player.y+=yspeed;
    view.x+=xspeed;
    view.y+=yspeed;
    hpDisp.x+=xspeed;
    hpDisp.y+=yspeed;
}


Of course you might want to make it better suited for your game, but the idea is still there. If you want a demo of any of these or you have any questions, just ask.

Re: Parenting Problem

PostPosted: Fri Dec 25, 2009 5:41 pm
by arcreamer
Thanks a lot! :D