How to get the X and Y of a clone

Game Editor comments and discussion.

How to get the X and Y of a clone

Postby phyzix5761 » Wed Feb 29, 2012 5:15 am

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!
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

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

Postby skydereign » Wed Feb 29, 2012 8:00 am

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

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

Postby phyzix5761 » Wed Feb 29, 2012 5:31 pm

Thanks man. That makes perfect sense. I'm going to give it a try.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

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

Postby phyzix5761 » Wed Feb 29, 2012 6:26 pm

How about when colliding with a clone? How would I go about getting that specific clone's x and y coords?
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

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

Postby lcl » Wed Feb 29, 2012 8:21 pm

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;
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

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

Postby skydereign » Wed Feb 29, 2012 11:18 pm

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

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

Postby phyzix5761 » Thu Mar 01, 2012 3:08 am

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?
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

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

Postby skydereign » Thu Mar 01, 2012 6:30 am

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


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest