开发者

OpenGL ES - selecting an object on a 2d world

If I draw thre开发者_如何学运维e rectangles to the surface, and "listen" to the onTouch event in a 2d Ortho world, then how can I identify which was the rectangle that was clicked?


If the triangles don't overlap you could keep track of the 3 xy points of each triangle in a triangle class object. then you can keep a list of those class objects to be compared later. then when the onTouch even is called you could see where the xy position of the finger is then compare it with the bounds of each rectangle to see if it is contained in it.

If it is within the bounds of one then you know that it is selected. If they overlap you just have to decide which is upfront. you can also keep track of order in the triangle objects if more that one triangle occupy the same space. then you would just choose the one that has the closest order with respect to the screen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜