Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mygdx.game;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.Sprite;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Label;
- import com.badlogic.gdx.scenes.scene2d.ui.Skin;
- import com.badlogic.gdx.utils.viewport.ScreenViewport;
- public class MyGdxGame extends ApplicationAdapter {
- private SpriteBatch batch;
- private OrthographicCamera camera;
- private ScreenViewport viewport;
- private Stage stage;
- private Skin skin;
- private Texture img;
- private Sprite sprite;
- private final float VIRTUAL_WIDTH = 160.0f;
- private float VIRTUAL_HEIGHT;
- @Override
- public void create () {
- batch = new SpriteBatch();
- camera = new OrthographicCamera();
- viewport = new ScreenViewport(camera);
- img = new Texture(Gdx.files.internal("badlogic.jpg"));
- sprite = new Sprite(img);
- sprite.setSize(20, 20);
- stage = new Stage(viewport);
- skin = new Skin(Gdx.files.internal("uiskin.json"));
- Label label = new Label("Hello World", skin);
- //label.setSize(40, 20); // bez wplywu
- label.setFontScale(0.3f); // dziala ale literki nachodza
- stage.addActor(label);
- }
- @Override
- public void resize(int width, int height)
- {
- stage.getViewport().update(width, height, true);
- VIRTUAL_HEIGHT = VIRTUAL_WIDTH * height / width;
- camera.setToOrtho(false, VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
- batch.setProjectionMatrix(camera.combined);
- }
- @Override
- public void render () {
- Gdx.gl.glClearColor(1, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- sprite.setPosition(VIRTUAL_WIDTH/2 - sprite.getWidth()/2, VIRTUAL_HEIGHT/2 - sprite.getHeight()/2);
- batch.begin();
- sprite.draw(batch);
- batch.end();
- stage.act();
- stage.draw();
- }
- @Override
- public void dispose () {
- batch.dispose();
- stage.dispose();
- skin.dispose();
- img.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment