com.badlogic.gdx.utils.viewport.FitViewport Java Examples

The following examples show how to use com.badlogic.gdx.utils.viewport.FitViewport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldRenderer.java    From xibalba with MIT License 6 votes vote down vote up
/**
 * Setup world renderer.
 *
 * @param worldCamera Instance of camera
 * @param batch       Instance of sprite batch
 */
public WorldRenderer(OrthographicCamera worldCamera, SpriteBatch batch) {
  this.worldCamera = worldCamera;
  this.batch = batch;

  viewport = new FitViewport(960, 540, worldCamera);

  playerDetails = ComponentMappers.player.get(WorldManager.player);
  playerAttributes = ComponentMappers.attributes.get(WorldManager.player);
  playerPosition = ComponentMappers.position.get(WorldManager.player);
  god = ComponentMappers.god.get(WorldManager.god);

  shadow = Main.asciiAtlas.createSprite("1113");
  question = Main.asciiAtlas.createSprite("1503");

  BitmapFont font = new BitmapFont();
  font.getData().setScale(.25f);
}
 
Example #2
Source File: ClientDiscoveryScreen.java    From killingspree with MIT License 6 votes vote down vote up
@Override
public void show() {
    client = new Client();
    client.start();
    font = game.getFont(120);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    ipAddresses = new ArrayList<MyButton>();
    markForDispose = false;
    addAllButtons();
    addIpButtons();
    pressedButton = false;
}
 
Example #3
Source File: MainMenuScreen.java    From xibalba with MIT License 6 votes vote down vote up
/**
 * Main Menu Screen.
 *
 * @param main Instance of main class
 */
public MainMenuScreen(Main main) {
  stage = new Stage(new FitViewport(960, 540));

  Table table = new Table();
  table.setFillParent(true);
  stage.addActor(table);

  ActionButton newGameButton = new ActionButton("N", "New Game");
  newGameButton.setKeys(Input.Keys.N);
  newGameButton.setAction(table, () -> main.setScreen(new YouScreen(main)));

  ActionButton quitButton = new ActionButton("Q", "Quit");
  quitButton.setKeys(Input.Keys.Q);
  quitButton.setAction(table, () -> Gdx.app.exit());

  table.add(new Label("[LIGHT_GRAY]Xibalba v0.1.0[]", Main.skin)).pad(0, 0, 10, 0);
  table.row();

  table.add(newGameButton).pad(0, 0, 10, 0);
  table.row();
  table.add(quitButton);

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}
 
Example #4
Source File: GameOverScreen.java    From Bomberman_libGdx with MIT License 6 votes vote down vote up
@Override
public void show() {
    viewport = new FitViewport(640, 480);
    stage = new Stage(viewport, batch);

    font = new BitmapFont(Gdx.files.internal("fonts/foo.fnt"));

    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
    Label gameOverLabel = new Label("Game Over", labelStyle);
    gameOverLabel.setPosition((640 - gameOverLabel.getWidth()) / 2, 226f);

    GameManager.getInstance().playMusic("GameOver.ogg", false);

    stage.addActor(gameOverLabel);

    stage.addAction(Actions.sequence(
            Actions.delay(1f),
            Actions.fadeOut(2f),
            Actions.run(new Runnable() {
                @Override
                public void run() {
                    game.setScreen(new MainMenuScreen(game));
                }
            })));

}
 
Example #5
Source File: RectangleCircleCollisionScreen.java    From ud406 with MIT License 6 votes vote down vote up
public RectangleCircleCollisionScreen() {
    startTime = TimeUtils.nanoTime();
    shapeRenderer = new ShapeRenderer();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    rectangles = new Array<Rectangle>(new Rectangle[]{
            new Rectangle(40, 40, 20, 20), // Middle
            new Rectangle(10, 40, 10, 20), // Left
            new Rectangle(70, 45, 20, 10) // Right
    });

    circles = new Array<OscillatingCircle>(new OscillatingCircle[]{
            new OscillatingCircle(50, 65, 7, 0, 40, 3), // High horizontal
            new OscillatingCircle(50, 35, 7, 0, 40, 3.1f), // Low horizontal
            new OscillatingCircle(50, 50, 3, MathUtils.PI / 4, 40, 5f), // Diagonal
            new OscillatingCircle(25, 50, 5, 0, 11, 7f), // Middle horizontal
    });
}
 
Example #6
Source File: GdxPdTests.java    From gdx-pd with Apache License 2.0 6 votes vote down vote up
@Override
public void create () 
{
	PdConfiguration config = new PdConfiguration();
	config.inputChannels = 1;
	Pd.audio.create(config);

	// new ScreenViewport()
	stage = new Stage(new FitViewport(800, 600));
	
	skin = new Skin(Gdx.files.internal("skins/uiskin.json"));
	
	Table root = new Table();
	root.defaults().pad(10);
	
	
	Gdx.input.setInputProcessor(stage);
}
 
Example #7
Source File: RectangleCircleCollisionScreen.java    From ud406 with MIT License 6 votes vote down vote up
public RectangleCircleCollisionScreen() {
    startTime = TimeUtils.nanoTime();
    shapeRenderer = new ShapeRenderer();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    rectangles = new Array<Rectangle>(new Rectangle[]{
            new Rectangle(40, 40, 20, 20), // Middle
            new Rectangle(10, 40, 10, 20), // Left
            new Rectangle(70, 45, 20, 10) // Right
    });

    circles = new Array<OscillatingCircle>(new OscillatingCircle[]{
            new OscillatingCircle(50, 65, 7, 0, 40, 3), // High horizontal
            new OscillatingCircle(50, 35, 7, 0, 40, 3.1f), // Low horizontal
            new OscillatingCircle(50, 50, 3, MathUtils.PI / 4, 40, 5f), // Diagonal
            new OscillatingCircle(25, 50, 5, 0, 11, 7f), // Middle horizontal
    });
}
 
Example #8
Source File: BubbleLevelScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    axisViewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);
    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);
    batch = new SpriteBatch();
    textViewport = new ScreenViewport();
    font = new BitmapFont();
    font.getData().setScale(TEXT_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    maxAcceleration = 0;
    minAcceleration = Float.MAX_VALUE;

}
 
Example #9
Source File: AccelerometerAxesScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    axisViewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);
    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);
    batch = new SpriteBatch();
    textViewport = new ScreenViewport();
    font = new BitmapFont();
    font.getData().setScale(TEXT_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    maxAcceleration = 0;
    minAcceleration = Float.MAX_VALUE;

}
 
Example #10
Source File: CircularMotion.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void create() {
    renderer = new ShapeRenderer();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    // Set the initialTime
    initialTime = TimeUtils.nanoTime();
}
 
Example #11
Source File: TalosDemo.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
    /**
     * We need a viewport for proper camerawork
     */
    viewport = new FitViewport(10f, 10f);
    viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);

    /**
     * We may need polygon sprite batch to render more complex VFX such us beams
     */
    batch = new PolygonSpriteBatch();

    /**
     * Prepare the texture atlas.
     * Normally just load Texture Atlas,  but for the sake of demo this will be creating fake atlas from just one texture.
     */
    TextureRegion textureRegion = new TextureRegion(new Texture(Gdx.files.internal("fire.png")));
    TextureAtlas textureAtlas = new TextureAtlas();
    textureAtlas.addRegion("fire", textureRegion);

    /**
     * Creating particle effect instance from particle effect descriptor
     */
    ParticleEffectDescriptor effectDescriptor = new ParticleEffectDescriptor(Gdx.files.internal("fire.p"), textureAtlas);
    effect = effectDescriptor.createEffectInstance();
}
 
Example #12
Source File: BubbleLevelScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    axisViewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);
    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);
    batch = new SpriteBatch();
    textViewport = new ScreenViewport();
    font = new BitmapFont();
    font.getData().setScale(TEXT_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    maxAcceleration = 0;
    minAcceleration = Float.MAX_VALUE;

}
 
Example #13
Source File: DifficultyScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    renderer = new ShapeRenderer();
    batch = new SpriteBatch();

    viewport = new FitViewport(Constants.DIFFICULTY_WORLD_SIZE, Constants.DIFFICULTY_WORLD_SIZE);
    Gdx.input.setInputProcessor(this);

    font = new BitmapFont();
    font.getData().setScale(Constants.DIFFICULTY_LABEL_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example #14
Source File: SplashScreen.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void show() {
    font = game.getFont(200);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
}
 
Example #15
Source File: OptionsScreen.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void show() {
    font = game.getFont(170);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    addAllButtons();
    buttonPressed = false;
}
 
Example #16
Source File: LoadingGameScreen.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
@Override
public void show () {
	camera = new OrthographicCamera();
	camera.position.set(GdxDemo3D.WIDTH * .5f, GdxDemo3D.HEIGHT * .5f, 0);
	camera.update();
	viewport = new FitViewport(GdxDemo3D.WIDTH, GdxDemo3D.HEIGHT, camera);
	shapeRenderer = new ShapeRenderer();
}
 
Example #17
Source File: LobbyScreen.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void show() {
    font = game.getFont(120);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    isServer = false;
    ipAddresses = new ArrayList<String>();
    markForDispose = false;
    startGame = false;
    host = "127.0.0.1";
}
 
Example #18
Source File: MainMenuScreen.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void show() {
    font = game.getFont(170);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    addAllButtons();
    final Preferences prefs = Gdx.app.getPreferences("profile");
    String name = prefs.getString("name");
    name = name.trim();
    if (name.length() == 0) {
        Gdx.input.getTextInput(new TextInputListener() {
            
            @Override
            public void input(String text) {
                prefs.putString("name", text);
                prefs.flush();
            }
            
            @Override
            public void canceled() {
            }
        }, "Enter name", "");
    }
}
 
Example #19
Source File: WorldRenderer.java    From killingspree with MIT License 5 votes vote down vote up
public void loadLevel(String level, boolean isServer, String name) {
    this.isServer = isServer;
    map = new TmxMapLoader().load(level);
    TiledMapTileLayer layer = (TiledMapTileLayer) map.
                                getLayers().get("terrain");
    VIEWPORT_WIDTH = (int) (layer.getTileWidth() * layer.getWidth());
    VIEWPORT_HEIGHT = (int) (layer.getTileHeight() * layer.getHeight());
    viewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, camera);
    renderer = new OrthogonalTiledMapRenderer(map);
    name = name.trim();
    if (name.length() == 0)
        name = "noname";
    if (name.length() >= 10){
        name = name.substring(0, 10);
    }
    ClientDetailsMessage clientDetails = new ClientDetailsMessage();
    clientDetails.name = name;
    clientDetails.protocolVersion = Constants.PROTOCOL_VERSION;
    if (isServer) {
        MapLayer collision =  map.
                getLayers().get("collision");
        for(MapObject object: collision.getObjects()) {
            worldManager.createWorldObject(object);
        }
        worldManager.addIncomingEvent(MessageObjectPool.instance.
                eventPool.obtain().set(State.RECEIVED, clientDetails));
    } else {
        client.sendTCP(clientDetails);
    }
    controls = new onScreenControls();
    
}
 
Example #20
Source File: DifficultyScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    renderer = new ShapeRenderer();
    batch = new SpriteBatch();

    viewport = new FitViewport(Constants.DIFFICULTY_WORLD_SIZE, Constants.DIFFICULTY_WORLD_SIZE);
    Gdx.input.setInputProcessor(this);

    font = new BitmapFont();
    font.getData().setScale(Constants.DIFFICULTY_LABEL_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example #21
Source File: DifficultyScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    renderer = new ShapeRenderer();
    batch = new SpriteBatch();

    // TODO: Initialize a FitViewport with the difficulty world size constant
    viewport = new FitViewport(Constants.DIFFICULTY_WORLD_SIZE, Constants.DIFFICULTY_WORLD_SIZE);
    Gdx.input.setInputProcessor(this);

    font = new BitmapFont();
    // TODO: Set the font scale using the constant we defined
    font.getData().setScale(Constants.DIFFICULTY_LABEL_SCALE);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example #22
Source File: GLTFPostProcessingExample.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
@Override
public void create() {
	
	sceneManager = createSceneManager();
	sceneManager.camera = camera = new PerspectiveCamera();
	camera.fieldOfView = 50;
	camera.near = 0.01f;
	camera.far = 10f;
	camera.position.set(1, 1, 1).scl(.1f);
	camera.up.set(Vector3.Y);
	camera.lookAt(Vector3.Zero);
	camera.update();
	
	// load user scene
	SceneAsset asset = new GLTFLoader().load(Gdx.files.internal("models/BoomBox/glTF/BoomBox.gltf"));
	sceneManager.addScene(new Scene(asset.scene));
	
	cameraController = new CameraInputController(camera);
	cameraController.translateUnits = .1f;
	Gdx.input.setInputProcessor(cameraController);

	viewport = new FitViewport(1000, 500, camera);
	
	// post processing
	if(postProcessingEnabled){
		fbo = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
		effectShader = new ShaderProgram(Gdx.files.classpath("shaders/effect.vs.glsl"), Gdx.files.classpath("shaders/effect.fs.glsl"));
		batch = new SpriteBatch();
	}
	
}
 
Example #23
Source File: NinePatchDemo.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void create() {
    batch = new SpriteBatch();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);

    // TODO: Load the platform texture (Look for the file in android/assets)
    platformTexture = new Texture("platform.png");

    // TODO: Initialize the NinePatch using the texture and the EDGE constant
    platformNinePatch = new NinePatch(platformTexture, EDGE, EDGE, EDGE, EDGE);
}
 
Example #24
Source File: SplashScreen.java    From libgdx-utils with MIT License 5 votes vote down vote up
@Override
public void show() {
	LibgdxUtils.assets.load("textures/splash.png", Texture.class);
	LibgdxUtils.assets.finishLoading();
	splash = LibgdxUtils.assets.get("textures/splash.png", Texture.class);

	LibgdxUtils.assets.load("skins/uiskin.json", Skin.class);
	LibgdxUtils.assets.load("icons/icons.atlas", TextureAtlas.class);

	camera = new OrthographicCamera();
	viewport = new FitViewport(splash.getWidth(), splash.getHeight(), camera);
}
 
Example #25
Source File: DepthScreen.java    From xibalba with MIT License 5 votes vote down vote up
/**
 * Screen for depth transitions.
 */
public DepthScreen() {
  stage = new Stage(new FitViewport(960, 540));

  Table table = new Table();
  table.setFillParent(true);
  stage.addActor(table);

  Label label = new Label(
      "Going " + (WorldManager.state == WorldManager.State.GOING_DOWN ? "Down" : "Up"),
      Main.skin
  );
  table.add(label);
}
 
Example #26
Source File: GeneratingWorldScreen.java    From xibalba with MIT License 5 votes vote down vote up
/**
 * World generation screen.
 *
 * @param main        Instance of Main
 * @param playerSetup Holds data for player creation
 */
public GeneratingWorldScreen(Main main, PlayerSetup playerSetup) {
  this.main = main;
  this.playerSetup = playerSetup;

  stage = new Stage(new FitViewport(960, 540));

  Table table = new Table();
  table.setFillParent(true);
  stage.addActor(table);

  table.add(new Label("HUN-CAME IS PREPARING.", Main.skin));

  new Thread(() -> Gdx.app.postRunnable(this::generateWorld)).start();
}
 
Example #27
Source File: PauseScreen.java    From xibalba with MIT License 5 votes vote down vote up
/**
 * Main Menu Screen.
 *
 * @param main Instance of main class
 */
public PauseScreen(Main main) {
  stage = new Stage(new FitViewport(960, 540));

  Table table = new Table();
  table.setFillParent(true);
  stage.addActor(table);

  ActionButton returnToGameButton = new ActionButton("ESC", "Return to Game");
  returnToGameButton.setKeys(Input.Keys.ESCAPE);
  returnToGameButton.setAction(table, () -> main.setScreen(Main.playScreen));

  ActionButton mainMenuButton = new ActionButton("M", "Main Menu");
  mainMenuButton.setKeys(Input.Keys.M);
  mainMenuButton.setAction(table, () -> {
    Main.playScreen.dispose();
    main.setScreen(new MainMenuScreen(main));
  });

  ActionButton quitButton = new ActionButton("Q", "Quit");
  quitButton.setKeys(Input.Keys.Q);
  quitButton.setAction(table, () -> Gdx.app.exit());

  table.add(new Label("[LIGHT_GRAY]PAUSED[]", Main.skin)).pad(0, 0, 10, 0);
  table.row();
  table.add(returnToGameButton).pad(0, 0, 10, 0);
  table.row();
  table.add(mainMenuButton).pad(0, 0, 10, 0);
  table.row();
  table.add(quitButton);

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}
 
Example #28
Source File: LoadingScreen.java    From xibalba with MIT License 5 votes vote down vote up
/**
 * Loading screen.
 *
 * @param main Instance of Main
 */
public LoadingScreen(Main main) {
  this.main = main;

  stage = new Stage(new FitViewport(960, 540));

  Table table = new Table();
  table.setFillParent(true);
  stage.addActor(table);

  label = new Label("", Main.skin);
  table.add(label);

  new Thread(() -> Gdx.app.postRunnable(this::loadAssets)).start();
}
 
Example #29
Source File: GdxCanvas.java    From seventh with GNU General Public License v2.0 5 votes vote down vote up
/**
     * 
     */
    public GdxCanvas() {
        this.batch = new SpriteBatch();
        this.color = new Color();
        this.tmpColor = new Color();
        
        this.shaderStack = new Stack<>();
        this.zoomStack = new Stack<>();
        
        this.camera = new OrthographicCamera(getWidth(), getHeight());
        this.camera.setToOrtho(true, getWidth(), getHeight());
        this.camera.position.x = this.camera.viewportWidth/2;
        this.camera.position.y = this.camera.viewportHeight/2;
        this.camera.update();
        
        this.viewport = new FitViewport(getWidth(), getHeight(), camera);
        this.viewport.apply();
                
        this.generators = new HashMap<String, FreeTypeFontGenerator>();
        this.fonts = new HashMap<String, BitmapFont>();
        this.bounds = new GlyphLayout();
                
        this.transform = new Matrix4();
        //this.batch.setTransformMatrix(transform);
                
        //Matrix4 projection = new Matrix4();
        //projection.setToOrtho( 0, getWidth(), getHeight(), 0, -1, 1);
        //this.batch.setProjectionMatrix(projection);
        
//        this.wHeight = getHeight();
        this.batch.setProjectionMatrix(this.camera.combined);
        
        this.shapes = new ShapeRenderer();
        //this.shapes.setTransformMatrix(transform);    
//        this.shapes.setProjectionMatrix(projection);
        //this.shapes.setProjectionMatrix(camera.combined);
        
        this.fbo = new FrameBuffer(Format.RGBA8888, getWidth(), getHeight(), false);
    }
 
Example #30
Source File: CyclicOverlap.java    From ud405 with MIT License 4 votes vote down vote up
@Override
public void create() {
    renderer = new ShapeRenderer();
    viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE);
}