Max Abrahamsson
Max Abrahamsson

Reputation: 1498

Override onTouchEvent function in GLES Renderer class?

im trying to make a simple game with Gles on android.

i've googled a lot for a solution but i couldnt find anyone mentioning how to implement ontouchevent in GLES.

here i how i implemented it so far... i know it's a silly way to do it :D but that was only way i could come up to set positionx variable free while there is no tapping

a brief summary of my Renderer Class...

public class GLmain implements Renderer {
public float mX,mY;
public boolean clicked;
public GLmain() 
    {
    clicked=false;
    }
    public void onDrawFrame(GL10 gl) {
      if(clicked)
      {
      positionx=mX;
      positiony=mY;
      clicked=false
      }
    }
}

in and Activity class

public class Alpha extends Activity {
private GLSurfaceView glSurface;
public float mousex,mousey;
public GLmain glrend=new GLmain();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    glSurface = new GLSurfaceView(this);    
    glSurface.setRenderer(glrend);
    setContentView(glSurface);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
    glrend.clicked=true;
    glrend.mX=event.getX();
    glrend.mY=event.getY();
    return true;
}}

Upvotes: 0

Views: 853

Answers (1)

CaseyB
CaseyB

Reputation: 25058

It's not a silly way to do it! You can't call directly into the Renderer because it's on a different thread so you need to have the Renderer poll for the information when it needs it.

Upvotes: 1

Related Questions