开发者

GLSurfaceView textured rect as button clicks

开发者 https://www.devze.com 2023-01-22 16:07 出处:网络
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 GLSur

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 kn开发者_StackOverflow社区ow 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


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();

    } 
0

精彩评论

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