1
\$\begingroup\$

i want to change the rendermode from RENDERMODE_WHEN_DIRTY to RENDERMODE_CONTINUOUSLY when i touch the screen.

WHAT i Need : Initially the object should be stationary. after touching the screen, it should move automatically. The motion of my object is a projectile motion ans it is working fine.

what i get : Force close and a NULL pointer exception.

My code :

public class BallThrowGLSurfaceView extends GLSurfaceView{

MyRender _renderObj;
Context context;
GLSurfaceView glView;

public BallThrowGLSurfaceView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    _renderObj = new MyRender(context);
    this.setRenderer(_renderObj);
    this.setRenderMode(RENDERMODE_WHEN_DIRTY);
    this.requestFocus();
    this.setFocusableInTouchMode(true);
    glView = new GLSurfaceView(context.getApplicationContext());
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    if (event != null)
    {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
        {
            if (_renderObj != null)
            {   Log.i("renderObj", _renderObj + "lll");
                // Ensure we call switchMode() on the OpenGL thread.
                // queueEvent() is a method of GLSurfaceView that will do this for us.
                queueEvent(new Runnable()
                {
                    public void run()
                    {
                        glView.setRenderMode(RENDERMODE_CONTINUOUSLY);      
                    }
                });
                return true;
            }
        }
    }
    return super.onTouchEvent(event);   
}

}

PS : i know that i am making some silly mistakes in this, but cannot figure out what it really is.

\$\endgroup\$
2
  • \$\begingroup\$ Could you add the NullPointerException.printStackTrace() to the question please? \$\endgroup\$ Sep 22, 2012 at 14:34
  • \$\begingroup\$ @DanielCarlsson it is giving at this line. glView.setRenderMode(RENDERMODE_CONTINUOUSLY); \$\endgroup\$ Sep 23, 2012 at 8:52

1 Answer 1

2
\$\begingroup\$

Override a method, setRendermode in ballThrowSurfaceview class and call that overridden method in your touchevent class.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .