-1

How can I render some things using SpriteBatch?

I tried to do in this way:

Main class

static SpriteBatch batch;

public void render() {
    Renderer.drawThing();
}

Renderer class

static drawThing() {
    main.batch.begin();
    //drawing some things
    main.batch.end();
}

And it throws a NullPointerException. What am I doing wrong?

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132

1 Answers1

1

From the bit of code you posted, you're not instantiated the SpriteBatch with batch = new SpritBatch(); If you run the code the way you have it here, then batch will be null which makes sense with the error you got.

Also, it's kind of hard to tell exactly what you're doing from your code, are you using the render() method provided by the LibGDX ApplicationListener?

Tekkerue
  • 1,497
  • 1
  • 11
  • 17