I want to render two textures side by side. And then consider such combination of these two textures as one sprite to use a single camera. I am able to render two textures side by side using SpriteBatch. How do I make the combination of these two textures into a single sprite and use camera to get different views?
Currently after I drew two textures with SpriteBatch, I'm trying to draw such SpriteBatch with a sprite. But I'm getting nullpointer when calling sprite.draw().
My ultimate goal is to render two images side by side to use as a background, and be able to use a camera on my background. Any ideas? THX
My current code:
public void create () {
batch = new SpriteBatch();
//create two texture for 1.jpg and 2.jpg
//use batch to draw them separately at different position
img_1 = new Texture("1.jpg");
img_2 = new Texture("2.jpg");
mWorld = new Sprite();
mWorld.setPosition(0, 0);
mWorld.setSize(WORLD_WIDTH,WORLD_HEIGHT);
float aspectRatio = (float)Gdx.graphics.getHeight() / (float)Gdx.graphics.getWidth();
camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_WIDTH * aspectRatio);
camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0);
camera.update();
}
@Override
public void render () {
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(this.img_1, 0, 0, WORLD_WIDTH/2, WORLD_HEIGHT);
batch.draw(this.img_2, WORLD_WIDTH/2, 0, WORLD_WIDTH/2, WORLD_HEIGHT);
//getting java nullpointer exception here
mWorld.draw(batch);
batch.end();
}