Reputation: 599
I make simply aplication in LibGDX. I have got two textures (background and sprite). The background is diplayed ok but I don't see the sprite. I have tried many solutions but nothing works. I don't know what is going on. Thanks for help.
Here is my code:
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
Texture.setEnforcePotImages(false);
camera = new OrthographicCamera(1, h/w);
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("graphic/bg1.png"));
bad = new Texture(Gdx.files.internal("graphic/b.png"));
layerOne = new TextureRegion(texture);
spriteb = new Sprite(bad);
rbg = new ParallaxBackground(new ParallaxLayer[]{
new ParallaxLayer(layerOne, new Vector2(),new Vector2()),
}, w, h,new Vector2());
}
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
rbg.render();
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
spriteb.setPosition(400, 200);
spriteb.draw(batch);
batch.end();
}
Upvotes: 1
Views: 1022
Reputation: 10320
Your camera viewport is too small for the Sprite position
camera = new OrthographicCamera(1, h/w);
...
spriteb.setPosition(400, 200);
The sprite is being rendered far outside of the viewport.
Try setting your camera like this:
camera = new OrthographicCamera(w, (h/w)*h);
Upvotes: 2