[Android Q&A, Help & Troubleshooting] Colliebudz:
problem is in CFGameView???

hi, i will make this short but to the point...

making a 2D app with a space theme and involves making a Game View which needs to use two images to make the background which is scrolling in portrait.

im stuck on the CFGameView part at the bottom.

i think i need to link them some how??

its blatantly simple and im just being thick..

cheers

-----------------CFGameRenderer-----------

import javax.microedition.khronos.egl.EGLConfig;

import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;

public class CFGameRenderer implements Renderer {

private CFBackground background = new CFBackground();

private CFBackground background2 = new CFBackground();

private float bgScroll1;

private float bgScroll2;

@Override

public void onDrawFrame(GL10 gl) { try { Thread.sleep(CFEngine.GAME_THREAD_FPS_SLEEP);

} catch (InterruptedException e) {

e.printStackTrace();

}

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

scrollBackground1(gl);

scrollBackground2(gl);

//ALL OTHER GAME DRAWING WILL BE CALLED HERE

gl.glEnable(GL10.GL_BLEND);

gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);

}

private void scrollBackground1(GL10 gl){

if (bgScroll1 == Float.MAX_VALUE){

bgScroll1 = 0f;

}

gl.glMatrixMode(GL10.GL_MODELVIEW);

gl.glLoadIdentity();

gl.glPushMatrix();

gl.glScalef(1f, 1f, 1f);

gl.glTranslatef(0f, 0f, 0f);

gl.glMatrixMode(GL10.GL_TEXTURE);

gl.glLoadIdentity();

gl.glTranslatef(0.0f, bgScroll1, 0.0f);

background.draw(gl);

gl.glPopMatrix();

bgScroll1 += CFEngine.SCROLL_BACKGROUND1;

gl.glLoadIdentity();

}

private void scrollBackground2(GL10 gl){

if (bgScroll2 == Float.MAX_VALUE){

bgScroll2 = 0f;

}

gl.glMatrixMode(GL10.GL_MODELVIEW);

gl.glLoadIdentity();

gl.glPushMatrix();

gl.glScalef(.5f, 1f, 1f);

gl.glTranslatef(1.5f, 0f, 0f);

gl.glMatrixMode(GL10.GL_TEXTURE);

gl.glLoadIdentity();

gl.glTranslatef(0.0f, bgScroll2, 0.0f);

background2.draw(gl);

gl.glPopMatrix();

bgScroll2 += CFEngine.SCROLL_BACKGROUND2;

gl.glLoadIdentity();

}

@Override

public void onSurfaceChanged(GL10 gl, int width, int height) {

gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL10.GL_PROJECTION);

gl.glLoadIdentity();

gl.glOrthof(0f, 1f, 0f, 1f, -1f, 1f);

}

@Override

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glClearDepthf(1.0f);

gl.glEnable(GL10.GL_DEPTH_TEST);

gl.glDepthFunc(GL10.GL_LEQUAL);

gl.glEnable(GL10.GL_BLEND);

gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);

background.loadTexture(gl, CFEngine.BACKGROUND_LAYER_ONE, CFEngine.context);

background2.loadTexture(gl, CFEngine.BACKGROUND_LAYER_TWO, CFEngine.context);

}

}

---------------- CFGame-------------

import android.app.Activity;

import android.opengl.GLSurfaceView.Renderer;

import android.os.Bundle;

public class CFGame extends Activity {

private CFGameView gameView;

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

gameView = new CFGameView(this);

setContentView(gameView);

}

@Override

protected void onResume() {

super.onResume();

gameView.onResume();

}

@Override

protected void onPause() {

super.onPause();

gameView.onPause();

}

}

--------------- CFGamView ---------------

import android.content.Context;

import android.opengl.GLSurfaceView;

public class CFGameView extends GLSurfaceView{

public CFGameView(Context context) {

super(context);

// TODO Auto-generated constructor stub

}

}

basically how do i properly create and extend the GLSurfaceView so it starts my game.

i keep getting this logcat error no matter what i try.

03-09 17:42:16.649: E/AndroidRuntime(17570): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blah blah/com.blah blah.CFGame}: java.lang.NullPointerException