I’m making a game in html5 canvas. I’m using jquery so I can get the click event and the clicks x,y coordinates. I have an array of unit objects and a tiled terrain (also an array). The unit objects have bounding box information, their position, and their type.
What is the most effecient way to map this click event to one of the units?
Loop through the unit objects and determine which was clicked like so:
Note, this won’t handle complex intersecting objects or z-index issues etc… just a starting point really.