Libgdx and the application for Android. Image as background

I am a newbie and am just starting my journey with libgdx. I would like to know how I can make image.png in 960x640 resolution as background in my game? Is it possible? Thanks for the advice and patience. Maybe you just have a textbook? This is my rendering class:

public void render() { texture = new Texture(Gdx.files.internal("E:/background.png")); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, 0, 0); batch.end(); } 

Second question. I need to insert two active images, an active tool, when I click on this image, the next image shows me on the screen. I want to perform an action when I click on this image.

+6
source share
2 answers

In your create () method, create a new texture that references your image.png, and then use the existing SpriteBatch to display it in the render () loop. Immediately after calling GL.clear (), go to the batch.draw (backgroundTexture, 0. 0) page and make sure that you are in the OrthographicProjection mode for your camera.

+7
source

first you need 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 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 the rendering methods between batch.begin and batch.end

sprite.draw(batch);

0
source

Source: https://habr.com/ru/post/909014/


All Articles