add actors to group

Game Editor comments and discussion.

add actors to group

Postby ESL » Mon Aug 30, 2010 5:33 am

How do take a bunch of actors and place them into a group?
ESL
 
Posts: 96
Joined: Mon Jun 28, 2010 2:05 am
Score: 1 Give a positive score

Re: add actors to group

Postby skydereign » Mon Aug 30, 2010 5:59 am

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

Re: add actors to group

Postby ESL » Mon Aug 30, 2010 6:12 am

I sort of understand that but how do I creat the group?
ESL
 
Posts: 96
Joined: Mon Jun 28, 2010 2:05 am
Score: 1 Give a positive score

Re: add actors to group

Postby skydereign » Mon Aug 30, 2010 6:15 am

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

Re: add actors to group

Postby lcl » Mon Aug 30, 2010 12:38 pm

Skydereign, you are a genius!! :D
Good job! 1+ for you. :wink:
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron