Page 1 of 1

add actors to group

PostPosted: Mon Aug 30, 2010 5:33 am
by ESL
How do take a bunch of actors and place them into a group?

Re: add actors to group

PostPosted: Mon Aug 30, 2010 5:59 am
by skydereign
If you want to contain a list of actors, I suggest storing their Actor *s in an array, or similar. You can do that or store their clonenames in an array, and get any Actor * by using getclone. This way if you want your functions to act on all actors within the group, you just use a loop.
Code: Select all
Actor * groupA[10];

void
moveGroup (int X, int Y)
{
    for(i=0;i<10;i++)
    {
        groupA[i]->x+=X;
        groupA[i]->y+=Y;
    }
}


If you need to use a built in function, you can access the individual actors like this.
Code: Select all
ChangeAnimation(groupA[i]->clonename, "animationName", FORWARD);


Here are two ways to set the array.
Code: Select all
groupA[0] = CreateActor("actorName", "animationName", "(none)", "(none)", 0, 0, true);
// this creates actorName and groups it into the array

// if the actor is already created you will have to use getclone, or getclone2
groupA[0] = getclone("actorClonename");

Re: add actors to group

PostPosted: Mon Aug 30, 2010 6:12 am
by ESL
I sort of understand that but how do I creat the group?

Re: add actors to group

PostPosted: Mon Aug 30, 2010 6:15 am
by skydereign
That first bit of code is meant to be in global code. You have to declare it there. The size of the array is equal to the max number of actors in the group. Just put it there, give the script a name, and click add.

Global Code
Code: Select all
Actor * groupName[groupSize];


Also if you want to remove an actor from the group, just say the fifth actor, you can either set a different actor to it, or do this.
Code: Select all
groupName[5] = NULL;

Re: add actors to group

PostPosted: Mon Aug 30, 2010 12:38 pm
by lcl
Skydereign, you are a genius!! :D
Good job! 1+ for you. :wink: