我刚刚学习了OpenGL,我正在使用OpenGL开发游戏。我不知道如何将OnTouch Event实现为image&移动图像我使用OpenGL文档示例OpenGLES 0.1但未完成
答案 0 :(得分:1)
见下面的代码 -
@Override
public boolean onTouchEvent(MotionEvent event)
{
mX = (int) event.getX();
mY = (int) event.getY();
return super.onTouchEvent(event);
}
并按照此tutorial.它可以帮助您。
答案 1 :(得分:1)
此链接非常有助于理解OpenGL中的TouchEvent概念
答案 2 :(得分:1)
默认情况下,您可以使用以下代码处理活动中的触摸,
@Override
public boolean onTouch(View v, MotionEvent event) {
final float mouseSensitivity = 0.5f;
if(event.getAction()==MotionEvent.ACTION_DOWN){
startX = event.getX();
startY = event.getY();
} else if(event.getAction()==MotionEvent.ACTION_UP){
startX = 0.0f;
startY = 0.0f;
} else if(event.getAction()==MotionEvent.ACTION_MOVE){
graphicsRenderer.rotate((startY - event.getY()) * mouseSensitivity,(startX - event.getX()) * mouseSensitivity);
startX = event.getX();
startY = event.getY();
}
return true;
}
// Where startX and startY are global int variables;
为了处理GLSurface视图,请执行此操作,
class ClearGLSurfaceView extends GLSurfaceView {
public ClearGLSurfaceView(Context context) {
super(context);
mRenderer = new ClearRenderer();
setRenderer(mRenderer);
}
public boolean onTouchEvent(final MotionEvent event) {
queueEvent(new Runnable(){
public void run() {
mRenderer.setColor(event.getX() / getWidth(),
event.getY() / getHeight(), 1.0f);
}});
return true;
}
ClearRenderer mRenderer;
}
答案 3 :(得分:0)
首先,你实现了覆盖方法onTouchMethod,然后你就可以看到触摸每一个动作,如向下,向上和触摸时移动。
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN){
Log.i(TAG,"Action Down");
} else if(event.getAction()==MotionEvent.ACTION_UP){
Log.i(TAG,"Action Up");
} else if(event.getAction()==MotionEvent.ACTION_MOVE){
Log.i(TAG,"Action Move");
}
return true;
}