   the final peak
  yo,im making an rtsi got pretty much everything prepped for content creationexcept for unit selectionim not talking about drag selectjust basic click A unit select A unitits 2d and in sdl(of course ^_^)im using hex tiles for landscape and pathing but i dont want to bind one unit per tile (i think thats cheap and lame and bad)i wanna impliment per pixel spacing of the units to keep them separatedso that helps horizontallybut not verticallywhere i have the unit overlapwhat are some of the techniques you guys use to deside which unit to select?i have a lot of game programming books -- even games with RTS in the titlebut they seem to glance over this step -- or immdediatly skip to 3d graphics where it then becomes a bit easier to do (for me(in my mind(as ive never tried it(XD)))thx in advance   
  I'm moving this to Game Programming as it's generally not SDL specific.The simple answer is just to take the pixel-coordinate of the mouse click, then go through all your units to see which one covers that area. If that won't work, you'll need to go into more detail about how you're representing unit positions.   ;  Yep, like Kylotan says, ask each unit whether the clicked position is 'on' that unit. If there are no units that say yes, you haven't selected anything; if there are more than one then you can either select them all, or the one 'closest' to the camera (typically an air unit first, then a tank, then an infantryman), or the one for which the click was nearest to the centre, or some other way of choosing between them.As for deciding whether a click is 'over' a unit or not, many games just have a simple bounding shape (rectangle or ellipse for a 2D game) for each unit.   ;  I don't think hex tiles are the best for this, because your units either can't move up and down or can't move left and right. I guess I can see how people would want to use them in a turn based strategy (if they want units to be able to be surrounded by 6 others), but in a RTS I think a square grid with 8 way movement is the best.   ;  If you're using tiles just to place buildings, which is quite likely given that the OP says he's using pixel placement for units, a non-rectilinear grid can give a more natural look.   ;  in addition i have read that hex pathfinding is generally much fasteri also have a few algorithims for easy dithering that wouldnt be possible using the square grid because of non congruent edges...hmm i dont know if thats a real term...basically the diagonals add a whole new level of complexity to dithering my tiles together that i dont have the time or manpower to createthis is a 'first-release' for me, and i expect it to be rather crude...so here is what im going to doim using SDL so ever surface is bound by a SDL_Rectim just going to calculate if the mouse click was within any of the units' SDL_Rect.  if it was then i will add it to the selection list. then i will sort that list by y coordinate so that the unit farthest down on the screen gets priority of selection.  this is useful if you have one unit on top of another i think...the problem is that i have to check every units location in the entire game every time i click my mouse for selection...granted i dont click the mouse very often but it just seems like an 'out-of-the-way' method. but i cant seem to come up with a better technique, plus it seems to be the most suggested method.i am unsettled by the lack of direct vertical movement though and hate the thought of pointless zig-zag paths -- but pathfinding options is another topic which i will start once i have unit selection completedthanks for everyones time -- kry -- sorry for the SDL specific post im just so used to going to alt game libs that i didnt think about it.   ;Quote:Original post by cwyersthe problem is that i have to check every units location in the entire game every time i click my mouse for selection...granted i dont click the mouse very often but it just seems like an 'out-of-the-way' method. but i cant seem to come up with a better technique, plus it seems to be the most suggested method.How about this.. Split your map up into zones. These zones can represent any part of the map, any number of tiles, any shape area etc. When a unit is placed or moved, check what zone it is within and add it to a pool of units that are within that zone (removing from the previous zone if the unit changes zones of course). When the mouse is clicked, check what zone the mouse was clicked inside of, and ask the units within that zone if they were clicked.This way, you might have 1,000 units in the game in total, but a particular zone might only contain 50 units meaning a saving of 950 bounding box checks. If that doesn't make enough sense to you then let me know and I'll happily explain further.   ;  Well, there is something you can do so that you don't have to check the coordinates against every unit. You can divide the map into rectangles or something of that sort. Let's say that you divide into 4 rectangles:A BC DAnd let's say the user clicks in the bottom right corner of the map. Then you know that you only have to check the units in rectangle D and ignore the other ones. You can update the unit's rectangle position when they move or something. You can also use this technique for collision detection and rendering.Edit: looks like I got beat :)   ;  thats a great idea guysthanks for helpin me out!++ranks   