Shouldn't be a problem, it's just a question of implementation.
XNA can certainly handle cursor location, mouse clicks and dragging. It's up to you to draw the box and figure out what objects are within in. Then its just a matter of assigning orders to those units. (I assume this is for a RTS game )
Nick, I'm surprised we can agree when I graduated from SVSU in
Saginaw and I see you are from Grand Valley. :-P (BTW, I
wasn't sure if you could make a bounding box out of that rectangle that
you draw but since you can that makes things much easier!)
Here is an idea for you. Since I haven't actually done it yet, I'm not sure if this is the best way to go about this.
Take the point where the user clicked and started dragging, and draw a
line that starts at the click point and goes on the Y to wherever the
mouse currently is (keep x at 0). Draw another line that does the
same but reversed (draw on X, keep y at 0). Also, draw a line
from the current mouse position up to the x that you started at and on
the y to where you started at. That will give you a rectangle on
your screen that will move when you move the mouse. When you
detect that the mouse button has been lifted, change those 4 lines into
a box(rectangle ), and loop through every unit on your screen to see if
its in that box. I hope thats close because I wouldn't want to
mislead someone.
The bounding box idea sounds the best. It would be making a
bounding box with the rectangle and then calling Intersects() for the
box against all the units. If intersects equals true then add it
to the group!
Calvin: That's pretty much how I would do it. You could also use XNA's BoundingBox class to help with determining which units are in the box (which you could make from a BoundingBox).
As far as grouping them, you could use subclass a System.Collections.ObjectModel.Collection<>. Then put the units into that. That would be my recommendation. Just create one and all all the intersecting units into it. Then you could make methods for your class like SetTarget() which would in turn set the target for all your units to a place. It would be an easy way to distribute methods to all the units.
Grouping units like in a RTS game
Moim Hossain
XNA can certainly handle cursor location, mouse clicks and dragging. It's up to you to draw the box and figure out what objects are within in. Then its just a matter of assigning orders to those units. (I assume this is for a RTS game )
Steve_j_maas
crazyabtdotnet
divya mittal
zx5000
Take the point where the user clicked and started dragging, and draw a line that starts at the click point and goes on the Y to wherever the mouse currently is (keep x at 0). Draw another line that does the same but reversed (draw on X, keep y at 0). Also, draw a line from the current mouse position up to the x that you started at and on the y to where you started at. That will give you a rectangle on your screen that will move when you move the mouse. When you detect that the mouse button has been lifted, change those 4 lines into a box(rectangle ), and loop through every unit on your screen to see if its in that box. I hope thats close because I wouldn't want to mislead someone.
sorsh
vbnet101
Mandana
oops, sorry. missed that.
Andrew Buyan
MNDANG
As far as grouping them, you could use subclass a System.Collections.ObjectModel.Collection<>. Then put the units into that. That would be my recommendation. Just create one and all all the intersecting units into it. Then you could make methods for your class like SetTarget() which would in turn set the target for all your units to a place. It would be an easy way to distribute methods to all the units.
NickNotYet
ROBSR