Page 1 of 1

actors in a rectangle

PostPosted: Sat May 06, 2006 6:32 am
by DilloDude
Does someone know how to find all actors in a rectangular region dragged by the mouse, and check an actor variable in each, and find all of them with the variable set to a certain value, and return the first n of them in an array? The application is a rts type game, where you select units. You drag a box, and I can use a canvas to show it, but when you release the mouse button, all units in the region are selected. So if their clonenames are in an array, I can access things from there. But rather than go through each unit and find if it's in the region, it would be simpler (if possible) to find all actors in the region and check if they are a unit.
Any ideas? Well, while youwork on it, I'll start with some animations and think of some other ideas for things to put in it.

PostPosted: Sat May 06, 2006 9:29 pm
by makslane
I think a good solution is you use the collision events in the canvas actor with the units.

When you begin draw the rectangle in the canvas (in a Mouse Button Down event), you can set a variable, like selectUnits = 1, and in the Collision event, make this test:

Code: Select all
if(selectUnits) 
{
   //create the selected varibale as integer, actor (in the variables button on script editor) 
   collide.selected = 1; 
}


Don't forget make selectUnits = 0 in the Mouse Button Up event for the canvas actor.

PostPosted: Sun May 07, 2006 5:17 am
by DilloDude
One problem: That will select everything it touches, and if you drag it elsewhere, they might not be inside it. But then you could go through the list of what is selected and find if it is in the region and if not, remove it from the selected list. Then you just need to move everything in the list after it to move back one position.

PostPosted: Sun May 07, 2006 11:21 am
by DilloDude
I have decided on a solution: cycle through all clones of each unit and check xscreen and yscreen coordinates, and if ti is within the region, do the necesary actions to select it. As I will only have four types of units it isn't too bad.