views:

51

answers:

1

I just want to ask a simple question related the GLSurfaceView and drawn objects on it. I am drawing a rect and bind a texture to it. It works great. Then, the textured rect I am drawing is on a GLSurfaceView. I am drawing a "button"-like object for which I should know whether the user clicked on the button or not.

I imagined that like this: if the user taps the screen and the .y of the tap are in the rect of the drawn object (in my case the button), I need another operation to be performed (i.e. change another view or so...). Is my idea correct?

Now the question: How do I handle user interactions? And how can I get the Rect of the drawn object (button) maped on the GLSurfaceView (i.e. Rect(120, 80)) so that I can then check whether the user clicked the button or not? Or there is some other approach.

Also I am interested in the following: I have in mind to make my application full opengl es based. I won't use Button views from Android. I am working with big textures and I think OpenGL ES is the better way to do it since animations via translations and rotations and scaling are much easier to handle. Am I right?

Thanks

A: 

You can use onTouchEvent to get the x and y points where user touches.

   @Override
   public boolean onTouchEvent(MotionEvent event) {

     float x = event.getX();
     float y = event.getY();

    } 
krunal shah
This has nothing to do with my initial question. Capturing where the user has clicked is one thing, mapping it on GLSurfaceView is different.