actors in a rectangle

Game Editor comments and discussion.

actors in a rectangle

Postby DilloDude » Sat May 06, 2006 6:32 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby makslane » Sat May 06, 2006 9:29 pm

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.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby DilloDude » Sun May 07, 2006 5:17 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Sun May 07, 2006 11:21 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest