libgdx and android application. Image as background

你。 提交于 2019-12-03 16:11:46

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.

first you have to set the view port do this in your create method

`float scrw = 960; float scrh = 640;

    camera = new OrthographicCamera();
    camera.viewportHeight = scrh;
    camera.viewportWidth = scrw;

    camera.position.set(camera.viewportWidth * .5f,
            camera.viewportHeight * .5f, 0f);
    camera.update();`

create a texture

texture = new Texture("data/background.png");

put this texture in a sprite like this

sprite=new sprite(texture);

and then set the size like this

sprite.setsize(960,640);

and draw it in your render methods between batch.begin and batch.end

sprite.draw(batch);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!