Search code examples
javaandroidlibgdx

libGdx - image background


I have problem with background in libGdx. I try solve mine problem with this:

"In your create() method, create a new Texture referencing your image.png, and then use your existing SpriteBatch to render it in the render() loop. Immediately after your GL.clear() call, go your batch.draw(backgroundTexture, 0. 0) and make sure you're in OrthographicProjection mode for your camera."

I do this:

    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        camera.update();
        batch.setProjectionMatrix(camera.combined);
        batch.begin();
            
        batch.draw(image, 250, 200);
        batch.draw(backGroundImage, 0, 0);
            
        batch.end();

"image" is mine normal Texture (it's simple image), "backGround" is ofc. mine background. I have "backGround" apply in mine create() method. Mine camer is on camera = new OrthographicCamera();. Here is what I see: ... I need 10 points of reputation to add image :<... Image is to short and cut on lef and right... What I doing wrong. On this solution here, Shinzul said something about loop in in render(), maybe this is mine problem but I dont know how to fix this.


Solution

  • I think you should draw your backgroung image first.

    Besides I think you should look at some tutorials, e.g. https://github.com/libgdx/libgdx/wiki/Spritebatch%2C-Textureregions%2C-and-Sprites. It explains same basic concepts of libgdx.