Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Test.game;
- import com.badlogic.gdx.Game;
- 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.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.graphics.g2d.TextureAtlas;
- import com.badlogic.gdx.scenes.scene2d.Actor;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Image;
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
- import com.badlogic.gdx.utils.viewport.StretchViewport;
- import java.awt.TextArea;
- public class Main extends Game {
- private int VIRTUAL_WIDTH = 600; <<== Virtual Width
- private int VIRTUAL_HEIGHT = 900; <<== Virtual Height
- OrthographicCamera cam;
- Stage stage;
- TextureAtlas atlas;
- Image Logo;
- @Override
- public void create () {
- stage = new Stage(new StretchViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT)); <<= give it the Width + Height
- cam = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT); <== give it the Width + Height
- atlas = new TextureAtlas("LoadingScreen.pack");
- Logo = new Image(atlas.findRegion("Logo1"));
- stage.addActor(Logo);
- }
- @Override
- public void resize(int Width, int Height) {
- Width = VIRTUAL_WIDTH; <<== set Width to VirtualWidth
- Height = VIRTUAL_HEIGHT; <<== set Height to VirtualHeight
- System.out.println("Width" + Width + "Height" + Height);
- System.out.println("Screen Width" + Gdx.graphics.getWidth() + "Screen Height" + Gdx.graphics.getHeight());
- stage.getViewport().update(Width, Height, true); <<== Update the vieuwport
- /* here i tried to see if it works by setting it center and making it have 50 width on all sides, atleast i thought.*/
- Logo.setSize(500, 800);
- Logo.setX(Width / 2 - Logo.getWidth() / 2);
- Logo.setY(Height / 2 - Logo.getWidth() / 2);
- Logo.setOrigin(Logo.getWidth() / 2, Logo.getHeight() / 2);
- }
- @Override
- public void render () {
- Gdx.gl.glClearColor(1, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- stage.act();
- stage.draw();
- }
- @Override
- public void dispose() {
- atlas.dispose();
- stage.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment