Parenting Problem

Non-platform specific questions.

Parenting Problem

Postby arcreamer » Fri Dec 25, 2009 7:11 am

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 :)
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score

Re: Parenting Problem

Postby skydereign » Fri Dec 25, 2009 8:47 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Parenting Problem

Postby arcreamer » Fri Dec 25, 2009 5:41 pm

Thanks a lot! :D
arcreamer
 
Posts: 398
Joined: Tue Jul 03, 2007 4:08 pm
Score: 9 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron