Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyGdxGame extends ApplicationAdapter {
- SpriteBatch batch;
- Sprite backg;
- Sprite board;
- OrthographicCamera camera;
- Viewport viewport;
- Viewport viewportBg;
- private final Texture bgt;
- @Override
- public void create () {
- batch = new SpriteBatch();
- bgt = new Texture(Gdx.files.internal("tmp/bg.png"));
- bgt.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
- board = new Sprite(new Texture(Gdx.files.internal("tmp/br.png")));
- board.setPosition(100, 100);
- board.setSize(200, 200);
- camera = new OrthographicCamera();
- viewportBg = new ScreenViewport(camera);
- // viewport = new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
- viewport = new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
- }
- @Override
- public void render(float dt) {
- camera.update();
- Gdx.gl.glClearColor(1, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- batch.begin();
- viewportBg.apply(true);
- batch.setProjectionMatrix(camera.combined);
- batch.draw(bgt, 0, 0, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- viewport.apply(true);
- batch.setProjectionMatrix(camera.combined);
- board.draw(batch);
- batch.end();
- }
- @Override
- public void dispose() {
- batch.dispose();
- }
- @Override
- public void resize(int width, int height) {
- viewport.update(width, height);
- viewportBg.update(width, height);
- camera.position.set(width / 2, height / 2, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement