2013-06-26 91 views
-1

我想呈現一個簡單的紋理與4個不同的顏色squares.There在我的語法沒有錯誤。libgdx渲染惡意

例外:

Exception in thread "LWJGL Application" java.lang.NullPointerException 
    at com.bracco.thrive.ThriveGame.create(ThriveGame.java:21) 
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:132) 
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:112) 

代碼

package com.bracco.thrive; 

import com.badlogic.gdx.ApplicationListener; 
import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.graphics.GL10; 
import com.badlogic.gdx.graphics.OrthographicCamera; 
import com.badlogic.gdx.graphics.Texture; 
import com.badlogic.gdx.graphics.Texture.TextureFilter; 
import com.badlogic.gdx.graphics.g2d.Sprite; 
import com.badlogic.gdx.graphics.g2d.SpriteBatch; 
import com.badlogic.gdx.graphics.g2d.TextureRegion; 
import com.badlogic.gdx.Game; 
import com.bracco.thrive.world.WorldGeneration; 

public class ThriveGame extends Game { 

    WorldGeneration wGenerate; 

    @Override 
    public void create() {  
     wGenerate.createWorld(); 
    } 

    @Override 
    public void dispose() { 

    } 

    @Override 
    public void render() {  
    wGenerate.render(); 
    } 

    @Override 
    public void resize(int width, int height) { 
    } 

    @Override 
    public void pause() { 
    } 

    @Override 
    public void resume() { 
    } 
} 


    package com.bracco.thrive.world; 

import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.graphics.g2d.Sprite; 
import com.badlogic.gdx.graphics.g2d.SpriteBatch; 
import com.badlogic.gdx.graphics.GL10; 
import com.badlogic.gdx.graphics.Texture; 
public class WorldGeneration { 

    private SpriteBatch spriteBatch; 
    private int textureWidth,textureHeight; 
    private boolean debug = false; 
    private Texture texture; 



    public void createWorld(){ 
     spriteBatch = new SpriteBatch(); 
     texture = new Texture(Gdx.files.internal("data/textures/basictextures.png")); 
    } 



    public void render(){ 
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
      spriteBatch.begin(); 
      drawTexture(); 
      spriteBatch.end(); 
     } 

    private void drawTexture() 
    { 
     spriteBatch.draw(texture, 0, 16, 0, 16, 16, 16, 1, 1); 

    } 
} 
+0

您從不實例化'wGenerate'。 –

回答

1

類WorldGeneration的對象不進行。

WorldGeneration wGenerate; 

@Override 
public void create() {  
wGenerate=new WorldGeneration(); 

    wGenerate.createWorld(); 
}