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

The following examples show how to use com.badlogic.gdx.utils.viewport.StretchViewport. 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: BattleScreen.java    From Norii with Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
	resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	mapMgr.getCurrentTiledMap();

	multiplexer.addProcessor(currentMap.getTiledMapStage());
	Gdx.input.setInputProcessor(multiplexer);

	setupViewport(VISIBLE_WIDTH, VISIBLE_HEIGHT);
	mapCamera.position.set(currentMap.getMapWidth() / 2f, currentMap.getMapHeight() / 2f, 0f);
	mapRenderer = new OrthogonalTiledMapRenderer(mapMgr.getCurrentTiledMap(), Map.UNIT_SCALE);
	mapRenderer.setView(mapCamera);
	currentMap.makeSpawnParticles();

	final StretchViewport vp = new StretchViewport(VISIBLE_WIDTH, VISIBLE_HEIGHT, mapCamera);
	currentMap.getTiledMapStage().setViewport(vp);
	Player.getInstance().getEntityStage().setViewport(vp);
	aiTeam.getEntityStage().setViewport(vp);
}
 
Example #2
Source File: AMScreen.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
    super.show();
    layout = new GlyphLayout();
    font = new NativeFont(new NativeFontPaint(25));
    font.appendText("正在加载...0123456789%");
    font.setColor(Color.BLACK);
    layout.setText(font, "正在加载...100%");

    stage = new Stage(new StretchViewport(1280, 720));

    assetManager = new AssetManager();
    assetManager.setLogger(new Logger("log", Logger.DEBUG));
    assetManager.setLoader(CocosScene.class, new CocosLoader(new InternalFileHandleResolver()));
    assetManager.load("mainscene/MenuScene.json", CocosScene.class);
}
 
Example #3
Source File: GameHud.java    From TerraLegion with MIT License 6 votes vote down vote up
public GameHud(GameScreen gameScreen, World world) {
    this.gameScreen = gameScreen;
    this.world = world;
    stageSb = new SpriteBatch();
    sb = new SpriteBatch();
    stage = new Stage(new StretchViewport(Settings.getWidth(), Settings.getHeight()), stageSb);
    moveControl = new JoystickControl(ResourceManager.getInstance().getTexture("joystickBg"), ResourceManager.getInstance().getTexture("joystickKnob"), 10, 20, 20, 200, 200);
    actionControl = new JoystickControl(ResourceManager.getInstance().getTexture("joystickBg"), ResourceManager.getInstance().getTexture("joystickKnob"), 10, 550, 20, 200, 200);
    stage.addActor(moveControl.getTouchpad());
    stage.addActor(actionControl.getTouchpad());
    stage.act(Gdx.graphics.getDeltaTime());

    camera = new OrthoCamera();
    InputController.getInstance().addInputProcessor(stage);

    bg = ResourceManager.getInstance().getTexture("bg");

    for (int i = 0; i < inventoryBoxes.length; i++) {
        inventoryBoxes[i] = new InventoryBox(world.getPlayer().getInventory().getItemStack(i, 0), 20 + (i * (InventoryBox.bg.getWidth() + 7)), Settings.getHeight() - InventoryBox.bg.getHeight() - 10);
    }
    inventoryBoxes[0].setSelected(true);
}
 
Example #4
Source File: MainMenuInterface.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
public void init(Game game, Assets assets) {
	hiScoreBuilder = new StringBuilder();
	savedStuff = new SavedStuff();
	skin = new Skin();
	stage = new Stage();
	batch = new SpriteBatch();
	cam = new OrthographicCamera(MainMenuScreen.WIDTH, MainMenuScreen.HEIGHT);
	Gdx.input.setInputProcessor(stage);
	stage.setViewport(new StretchViewport(MainMenuScreen.WIDTH, MainMenuScreen.HEIGHT));
	batch.setProjectionMatrix(cam.combined);
	this.game = game;
	this.assets = assets;
	
	loadMainMenuAssets();
	setUpSkin();
	createTable();
	createStageActors();
	addStageActorsToStage();
	setActorsToDefaults();
	addListenersToActors();
}
 
Example #5
Source File: UI.java    From Unlucky with MIT License 5 votes vote down vote up
public UI(final Unlucky game, Player player, ResourceManager rm) {
    this.game = game;
    this.player = player;
    this.rm = rm;

    viewport = new StretchViewport(Unlucky.V_WIDTH, Unlucky.V_HEIGHT, new OrthographicCamera());
    stage = new Stage(viewport, game.batch);

    shapeRenderer = new ShapeRenderer();
}
 
Example #6
Source File: UI.java    From Unlucky with MIT License 5 votes vote down vote up
public UI(GameScreen gameScreen, TileMap tileMap, Player player, ResourceManager rm) {
    this.game = gameScreen.getGame();
    this.gameScreen = gameScreen;
    this.tileMap = tileMap;
    this.player = player;
    this.rm = rm;

    viewport = new StretchViewport(Unlucky.V_WIDTH, Unlucky.V_HEIGHT, new OrthographicCamera());
    stage = new Stage(viewport, gameScreen.getBatch());

    shapeRenderer = new ShapeRenderer();
}
 
Example #7
Source File: AbstractScreen.java    From Unlucky with MIT License 5 votes vote down vote up
public AbstractScreen(final Unlucky game, final ResourceManager rm) {
    this.game = game;
    this.rm = rm;

    cam = new OrthographicCamera(Unlucky.V_WIDTH, Unlucky.V_HEIGHT);
    cam.setToOrtho(false);
    // the game will retain it's scaled dimensions regardless of resizing
    viewport = new StretchViewport(Unlucky.V_WIDTH, Unlucky.V_HEIGHT, cam);

    stage = new Stage(viewport, game.batch);
}
 
Example #8
Source File: GameCamera.java    From libgdx-2d-tutorial with MIT License 5 votes vote down vote up
public GameCamera (int width, int height) {
	cam = new OrthographicCamera();
	viewport = new StretchViewport(width, height, cam);
	viewport.apply();
	cam.position.set(width / 2, height / 2, 0);
	cam.update();
}
 
Example #9
Source File: DemoScreen.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
@Override
public void show() {
    super.show();
    stage = new Stage(new StretchViewport(DemoGame.GAME_WIDTH, DemoGame.GAME_HEIGHT));
    InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(stage);
    initDemoChange(multiplexer);
    Gdx.input.setInputProcessor(multiplexer);
    findAllDemos();
    defaultFont = Gdx.files.internal("share/MLFZS.TTF");
    changeDemo();
}
 
Example #10
Source File: DemoScreen.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
private void initDemoChange(InputMultiplexer multiplexer) {
    Stage demoChangeStage = new Stage(new StretchViewport(DemoGame.GAME_WIDTH, DemoGame.GAME_HEIGHT));
    Actor actor = new Actor();
    actor.setWidth(stage.getWidth());
    actor.setHeight(stage.getHeight());
    actor.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            updateCurrentIndex();
            changeDemo();
        }
    });
    demoChangeStage.addActor(actor);
    multiplexer.addProcessor(demoChangeStage);
}
 
Example #11
Source File: CraftingScreen.java    From TerraLegion with MIT License 5 votes vote down vote up
@Override
public void create() {
	camera = new OrthoCamera();
	camera.resize();

	stageSb = new SpriteBatch();
	stage = new Stage(new StretchViewport(Settings.getWidth(), Settings.getHeight()), stageSb);

	//CATEGORY BUTTONS
	stage.addActor(toolCategoryBtn.getImageButton());
	stage.addActor(furnitureCategoryBtn.getImageButton());

	ScrollPane.ScrollPaneStyle paneStyle = new ScrollPane.ScrollPaneStyle();
	paneStyle.background = new TextureRegionDrawable(new TextureRegion(ResourceManager.getInstance().getTexture("invStageBg")));
	//paneStyle.vScrollKnob = new TextureRegionDrawable();
	//paneStyle.hScroll = paneStyle.hScrollKnob = paneStyle.vScroll = paneStyle.vScrollKnob;

	Table craftingContainer = CachePool.getTable();
	usedTablesCache.add(craftingContainer);
	float startX = (Settings.getWidth() / 2) - 255;
	craftingContainer.setBounds(startX, 0, 370, Settings.getHeight() - 61);

	craftingTable = CachePool.getTable();
	stage.addListener(new CraftingButtonClickListener(stage, craftingTable, craftingContainer.getX(), craftingContainer.getY()));
	usedTablesCache.add(craftingTable);

	pane = new ScrollPane(craftingTable, paneStyle);
	craftingContainer.add(pane).width(370).height(Settings.getHeight() - 61);
	craftingContainer.row();
	stage.addActor(craftingContainer);

	itemNameLabel = new Label("", ResourceManager.getInstance().getFont("font"), startX + 370 + 10, Settings.getHeight() - 61 - 35, false);
	itemInfoLabel = new MultilineLabel("", ResourceManager.getInstance().getFont("font"), startX + 370 + 10, Settings.getHeight() - 61 - 85, false);

	populateCraftableItems(toolCategoryBtn.getCategory());

	InputController.getInstance().addInputProcessor(stage);
}
 
Example #12
Source File: InventoryScreen.java    From TerraLegion with MIT License 4 votes vote down vote up
@Override
public void create() {
	camera = new OrthoCamera();
	camera.resize();

	stageSb = new SpriteBatch();
	stage = new Stage(new StretchViewport(Settings.getWidth(), Settings.getHeight()), stageSb);

	ScrollPane.ScrollPaneStyle paneStyle = new ScrollPane.ScrollPaneStyle();
	paneStyle.background = new TextureRegionDrawable(new TextureRegion(ResourceManager.getInstance().getTexture("invStageBg")));
	//paneStyle.vScrollKnob = new TextureRegionDrawable();
	//paneStyle.hScroll = paneStyle.hScrollKnob = paneStyle.vScroll = paneStyle.vScrollKnob;

	Table invContainer = CachePool.getTable();
	invContainer.setCullingArea(new Rectangle(0, 0, Settings.getWidth(), Settings.getHeight()));
	usedTablesCache.add(invContainer);

	float startX = (Settings.getWidth() / 2) - 255;
	invContainer.setBounds(startX, 0, 370, Settings.getHeight() - 61);

	table = CachePool.getTable();
	table.setCullingArea(new Rectangle(0, 0, Settings.getWidth(), Settings.getHeight()));
	table.addListener(new InventoryButtonClickListener(table));
	usedTablesCache.add(table);

	ScrollPane pane = new ScrollPane(table, paneStyle);
	pane.setCancelTouchFocus(false);
	pane.setCullingArea(new Rectangle(0, 0, Settings.getWidth(), Settings.getHeight()));

	invContainer.add(pane).width(370).height(Settings.getHeight() - 61);
	invContainer.row();
	stage.addActor(invContainer);

	itemNameLabel = new Label("", ResourceManager.getInstance().getFont("font"), startX + 370 + 10, Settings.getHeight() - 61 - 35, false);
	itemInfoLabel = new MultilineLabel("", ResourceManager.getInstance().getFont("font"), startX + 370 + 10, Settings.getHeight() - 61 - 85, false);

	for (int y = 0; y < inventory.getHeight(); y++) {
		for (int x = 0; x < inventory.getWidth(); x++) {

			ItemStack stack = inventory.getItemStack(x, y);
			ItemBox box = new ItemBox(stack, x, y, x + " " + y);
			InventoryDragListener dragListener = getDragListener(box);
			dragListener.setScrollPane(pane);
			dragListener.setTableHolder(table);
			dragListener.setInventory(inventory);
			box.addListener(dragListener);

			Cell<Table> cell = table.add((Table) box).width(60).height(60).padRight(10).padBottom(10);
			if (x == 0) {
				cell.padLeft(10);
			}
			if (y == 0) {
				cell.padTop(10);
			}
		}
		table.row();
	}
	InputController.getInstance().addInputProcessor(stage);
}