我为我的android游戏使用opengl es。我想抓住x和y的位置。我跟着一堆不同的教程,一切都会导致相同的结果:我无法从中得到任何东西。这个方法甚至不是我觉得奇怪的。所以,这里是我的GLSurfaceView类android ontouchevent opengl
class OpenGLES10SurfaceView extends GLSurfaceView {
//private final float TOUCH_SCALE_FACTOR = 180.0f/320;
public OpenGLES10Renderer mRenderer;
//static private float mPreviousX;
//static private float mPreviousY;
private static float _x;
private static float _y;
public OpenGLES10SurfaceView(Context context){
super(context);
// set the mRenderer member
mRenderer = new OpenGLES10Renderer(context);
setRenderer(mRenderer);
// Render the view only when there is a change
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
// MotionEvent reports input details from the touch screen
// and other input controls. In this case, you are only
// interested in events where the touch position changed.
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
mRenderer.setX(x);
return true;
}
}
}
我不能找到个到底是不对的,所以如果你能帮助这将极大地appriciated。如果您需要编码部分代码,请说明。
你记得在你的视图上设置OnTouchListener吗? – JoxTraex 2012-08-03 00:40:34
你能否在你的活动中包含你设置contentview的部分?另外,请尝试在活动中添加一个onTouchEvent(),如果没有任何视图使用该事件,则应该接收该事件,这可以帮助您调试问题。 – Aert 2012-08-03 02:58:31