-1

4 つの異なる色の正方形で単純なテクスチャをレンダリングしようとしています。構文にエラーはありません。

例外:

 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);

    }
}
4

1 に答える 1

1

クラス WorldGeneration のオブジェクトは作成されません。

 WorldGeneration wGenerate;

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

    wGenerate.createWorld();
}
于 2013-06-26T19:22:26.520 に答える