Page 1 of 1

How to get the X and Y of a clone

PostPosted: Wed Feb 29, 2012 5:15 am
by phyzix5761
Hey guys. I was hoping someone could help me out. How do I find out the X and Y coords of a clone of an actor? I know how to find the X and Y of the original actor but I don't see a way to get the previously mentioned for a clone. Thanks!

Re: How to get the X and Y of a clone

PostPosted: Wed Feb 29, 2012 8:00 am
by skydereign
You have to use getclone functions (namely getclone2). getclone is built in but the getclone2 functions are something you have to put in yourself.
Code: Select all
Actor*
getclone2 (char* name, int cindex)
{
    char buffer[30];
    sprintf(buffer, "%s.%d", name, cindex);
    return(getclone(buffer));
}


That way you can grab the Actor* of the specific clone. To get the x and y from an Actor* you can do the following.
Code: Select all
Actor* temp = getclone2("enemy", 5); // gets pointer to enemy.5
sprintf(text, "x: %lf\ty: %lf", temp->x, temp->y);

I just set it up to display the values, though you can set them as well. You also don't have to store the Actor* if you only need it for one instance.

Re: How to get the X and Y of a clone

PostPosted: Wed Feb 29, 2012 5:31 pm
by phyzix5761
Thanks man. That makes perfect sense. I'm going to give it a try.

Re: How to get the X and Y of a clone

PostPosted: Wed Feb 29, 2012 6:26 pm
by phyzix5761
How about when colliding with a clone? How would I go about getting that specific clone's x and y coords?

Re: How to get the X and Y of a clone

PostPosted: Wed Feb 29, 2012 8:21 pm
by lcl
For that you don't even need getclone2().
For accessing the collide actors variables in collision events just use collide.x etc. :D

Example:
Code: Select all
myCollideActorsX = collide.x;

Re: How to get the X and Y of a clone

PostPosted: Wed Feb 29, 2012 11:18 pm
by skydereign
collide is what makslane called an especial actor. In collision events you are given that struct which is the Actor that caused the collision event. Other especial actor labels are creator and parent, which can be used in any event.

Re: How to get the X and Y of a clone

PostPosted: Thu Mar 01, 2012 3:08 am
by phyzix5761
I tried using collide.y and it works perfectly on the original collide actor but when it collides with a clone of the original actor it reads the y coordinate of the original actor for some reason. Any way to get the clone's y coordinate on collision?

Re: How to get the X and Y of a clone

PostPosted: Thu Mar 01, 2012 6:30 am
by skydereign
In a collision event there are two actors, the event actor and the colliding actor. The actual collision event belongs to the event actor, and usually the event specifies which actors can trigger it. If you have one actor that collides with several other actors, each event is dealt with on an individual basis. Now if you have two clones colliding with each other, that counts as two collision events that are handled individually. So collide does exactly what it should, by getting the non-event actor's Actor struct.