use a Spritebatch, Textureregions, and Sprites

TextureRegion

TextureRegions can be created without a texture. This is useful if a region should be populated with a texture at another point in time. Doing so however bears the risk of a NullPointerException if this initialization is not done and the region is drawn. To prevent this, draw calls can be protected:

  1. private SpriteBatch spriteBatch = SpriteBatch();
  2. private TextureRegion textureRegion = new TextureRegion();
  3. @override
  4. public void render(float deltaTime)
  5. {
  6. spriteBatch.begin();
  7. if(textureRegion.getTexture() != null)
  8. {
  9. spriteBatch.draw(textureRegion, 0f, 0f, 1024f, 512f);
  10. }
  11. spriteBatch.end();
  12. }