Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

closed as not a real question by Byte56, Laurent Couvidou, Jonathan Hobbs, Trevor Powell, Josh Petrie Oct 19 '12 at 17:34

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Could you add the NullPointerException.printStackTrace() to the question please? –  Daniel Carlsson Sep 22 '12 at 14:34
    
@DanielCarlsson it is giving at this line. glView.setRenderMode(RENDERMODE_CONTINUOUSLY); –  Sid Sep 23 '12 at 8:52

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.