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

The following examples show how to use com.badlogic.gdx.utils.viewport.ScreenViewport. 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: MainScreen.java    From gdx-skineditor with Apache License 2.0 6 votes vote down vote up
public MainScreen(SkinEditorGame game) {
	this.game = game;
	
	barMenu = new MenuBar(game);
	barWidgets = new WidgetsBar(game);
	panePreview = new PreviewPane(game);
	paneOptions = new OptionsPane(game);
	stage = new Stage(new ScreenViewport());
	
	Table table = new Table();
	table.setFillParent(true);
	
	table.top().left().add(barMenu).expandX().fillX().colspan(2).row();
	table.top().left().add(barWidgets).expandX().fillX().colspan(2).row();
	table.top().left().add(paneOptions).width(420).left().fill().expandY();
	ScrollPane scrollPane = new ScrollPane(panePreview);
	table.add(scrollPane).fill().expand();
	stage.addActor(table);
	barWidgets.initializeButtons();
	

	
}
 
Example #2
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport, difficulty);

    Gdx.input.setInputProcessor(this);

    topScore = 0;
}
 
Example #3
Source File: ViewportsDemo.java    From ud405 with MIT License 6 votes vote down vote up
/**
     * Uncomment the following viewports one at a time, and check out the effect when you resize the desktop window.
     */
    @Override
    public void create() {
        camera = new OrthographicCamera();

        // Makes the size of the world match the size of the screen
        viewport = new ScreenViewport(camera);

        // Make the world fill the screen, regardless of aspect ratio
//        viewport = new StretchViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);

        // Make the world fill the screen, maintaining aspect ratio, but bits of the world may be cut off
//        viewport = new FillViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);

        // Fit the world inside the screen, adding black bars to pad out the extra space, maintaining aspect ratio
//        viewport = new FitViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);

        // Make the short axis of the world larger to fill the screen, maintaining aspect ratio
//        viewport = new ExtendViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);


        viewport.setScreenBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        renderer = new ShapeRenderer();
    }
 
Example #4
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport, difficulty);

    Gdx.input.setInputProcessor(this);

    topScore = 0;
}
 
Example #5
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport, difficulty);

    Gdx.input.setInputProcessor(this);

    topScore = 0;
}
 
Example #6
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport, difficulty);

    Gdx.input.setInputProcessor(this);

    topScore = 0;
}
 
Example #7
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    // TODO: Initialize icicles with the difficulty
    icicles = new Icicles(iciclesViewport);

    topScore = 0;
}
 
Example #8
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    hudViewport = new ScreenViewport();
    batch = new SpriteBatch();

    font = new BitmapFont();
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    // TODO: Initialize icicles with the difficulty
    icicles = new Icicles(iciclesViewport, difficulty);

    topScore = 0;
}
 
Example #9
Source File: IciclesScreen.java    From ud405 with MIT License 6 votes vote down vote up
@Override
public void show() {
    iciclesViewport = new ExtendViewport(Constants.WORLD_SIZE, Constants.WORLD_SIZE);

    renderer = new ShapeRenderer();
    renderer.setAutoShapeType(true);

    // TODO: Initialize the HUD viewport
    hudViewport = new ScreenViewport();

    // TODO: Initialize the SpriteBatch
    batch = new SpriteBatch();

    // TODO: Initialize the BitmapFont
    font = new BitmapFont();

    // TODO: Give the font a linear TextureFilter
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    player = new Player(iciclesViewport);
    icicles = new Icicles(iciclesViewport);

    // TODO: Set top score to zero
    topScore = 0;
}
 
Example #10
Source File: Examples.java    From Entitas-Java with MIT License 6 votes vote down vote up
@Override
public void create() {
    engine = new ExamplesEngine();
    entitas = new Entitas();

    preferencesManager.LOG_LEVEL = LogManager.LOG_DEBUG;
    AssetManager assetsManager = new AssetManager(new TestFileHandleResolver());
    engine.addManager(new AssetsManagerGDX(assetsManager, preferencesManager));
    engine.addManager(new PhysicsManagerGDX(new Vector2(0,-9.8f)));
    engine.addManager(new GUIManagerGDX(new ScreenViewport(),new BitmapFont(), engine));
    engine.addManager(new SceneManagerGDX(engine, entitas));
    engine.addManager(new LogManagerGDX(preferencesManager));
    engine.addManager(new InputManagerGDX(entitas, engine));
    engine.addManager(preferencesManager);

    game = new ExamplesGame(engine, new EventBusGDX(new MBassador()));
    game.init();
    game.pushState(new PlatformExampleState(engine, entitas));

}
 
Example #11
Source File: TestFloatingGroup.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
public void create () {
	VisUI.load();

	stage = new Stage(new ScreenViewport());
	final Table root = new Table();
	root.setFillParent(true);
	stage.addActor(root);

	TestWindow window = new TestWindow();
	TestCollapsible collapsible = new TestCollapsible();
	window.setKeepWithinParent(true);
	window.setPosition(110, 110);
	collapsible.setKeepWithinParent(true);
	collapsible.setPosition(200, 200);

	FloatingGroup floatingGroup = new FloatingGroup(1000, 600);
	floatingGroup.addActor(window);
	floatingGroup.addActor(collapsible);

	root.debugAll();
	root.left().bottom();
	root.add(floatingGroup).padLeft(100).padBottom(100);

	Gdx.input.setInputProcessor(stage);
}
 
Example #12
Source File: LevelScreen.java    From ninja-rabbit with GNU General Public License v2.0 6 votes vote down vote up
public LevelScreen(final NinjaRabbitGame game) {
	super(game);

	world = new World(new Vector2(0.0f, GRAVITY), true);
	hud = new StatusBar(game.getBatch(), game.getAssetsManager());

	BodyEditorLoader bodyLoader = new BodyEditorLoader(Gdx.files.internal(BODIES_DEFINITION_FILE));
	ninjaRabbit = EntityFactory.createNinjaRabbit(world, bodyLoader, game.getAssetsManager(), game.getPlayerStatus(), hud);
	LevelRenderer mapRenderer = LevelFactory.create(world, bodyLoader, game.getBatch(), game.getAssetsManager(), game.getPlayerStatus()
			.getLevel(),
			1 / NinjaRabbitGame.PPM);
	environment = EntityFactory.createEnvironment(world, game.getBatch(), mapRenderer, game.getAssetsManager(),
			game.getPlayerStatus(), (PlayerStatusObserver[]) null);
	viewport = new ScreenViewport();
	viewport.setUnitsPerPixel(1 / NinjaRabbitGame.PPM);
	viewport.setCamera(new BoundedCamera(0.0f,
			mapRenderer.getTiledMap().getProperties().get("width", Integer.class).floatValue()
					* mapRenderer.getTiledMap().getProperties().get("tilewidth", Integer.class).floatValue()
					/ NinjaRabbitGame.PPM));

}
 
Example #13
Source File: Filtering.java    From ud406 with MIT License 5 votes vote down vote up
@Override
public void create() {
    batch = new SpriteBatch();
    viewport = new ScreenViewport();
    nearest = new Texture("standing-right.png");
    linear = new Texture("standing-right.png");
    linear.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
 
Example #14
Source File: FPSCounterScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {

    // TODO: Initialize the SpriteBatch
    batch = new SpriteBatch();

    // TODO: Initialize the BitmapFont
    font = new BitmapFont();
    font.getData().setScale(2);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    // TODO: Initialize the ScreenViewport
    viewport = new ScreenViewport();
}
 
Example #15
Source File: CreditsScreen.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
	public void show() {
		retrieveAssets();
		Gdx.input.setInputProcessor(inputProcessor);

//		int wWidth = EngineAssetManager.getInstance().getResolution().portraitWidth;
//		int wHeight = EngineAssetManager.getInstance().getResolution().portraitHeight;

//		viewport = new ExtendViewport(wWidth, wHeight);
		viewport = new ScreenViewport();

		stringHead = 0;
		scrollY = 0;
	}
 
Example #16
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 #17
Source File: StatusBar.java    From ninja-rabbit with GNU General Public License v2.0 5 votes vote down vote up
public StatusBar(final Batch batch, final AssetManager assets) {
	overlay = new Stage(new ScreenViewport(), batch);

	Label.LabelStyle style = new Label.LabelStyle();
	style.fontColor = Color.WHITE;
	style.font = assets.get(Assets.HUD_FONT);
	style.font.setFixedWidthGlyphs(NUMBER_GLYPHS);

	collectiblesLabel = new Label(String.format(TWO_DIGITS, 0), style);
	livesLabel = new Label(String.format(TWO_DIGITS, 0), style);
	scoreLabel = new Label(String.format(EIGHT_DIGITS, 0), style);
	timeLabel = new Label(String.format(THREE_DIGITS, 0), style);

	TextureAtlas hudAtlas = assets.get(Assets.NINJA_RABBIT_ATLAS);

	Table table = new Table();
	table.add(new Image(hudAtlas.findRegion(SMALL_CARROT_REGION))).padRight(8.0f);
	table.add(collectiblesLabel).bottom();
	table.add(new Image(hudAtlas.findRegion(LIVES_REGION))).padLeft(15.0f);
	table.add(livesLabel).bottom();
	table.add(scoreLabel).expandX();
	table.add(new Image(hudAtlas.findRegion(TIME_REGION))).padRight(12.0f);
	table.add(timeLabel);
	table.setFillParent(true);
	table.top();
	table.pad(15.0f);

	overlay.addActor(table);
}
 
Example #18
Source File: LevelStartScreen.java    From ninja-rabbit with GNU General Public License v2.0 5 votes vote down vote up
public LevelStartScreen(final NinjaRabbitGame game) {
	super(game);
	PlayerStatus playerStatus = game.getPlayerStatus();
	stage = new Stage(new ScreenViewport(), game.getBatch());

	Label.LabelStyle style = new Label.LabelStyle();
	style.fontColor = Color.WHITE;
	style.font = game.getAssetsManager().get(Assets.HUD_FONT);

	TextureAtlas hudAtlas = game.getAssetsManager().get(Assets.NINJA_RABBIT_ATLAS);

	Label collectiblesLabel = new Label(String.format(TWO_DIGITS, playerStatus.getCollectibles()), style);
	Label livesLabel = new Label(String.format(LIVES_FORMAT, playerStatus.getLives()), style);
	Label scoreLabel = new Label(String.format(EIGHT_DIGITS, playerStatus.getScore()), style);
	Label timeLabel = new Label(String.format(THREE_DIGITS, playerStatus.getTime()), style);

	Table status = new Table();
	status.add(new Image(hudAtlas.findRegion(SMALL_CARROT_REGION))).padRight(4.0f);
	status.add(collectiblesLabel).bottom();
	status.add(scoreLabel).expandX();
	status.add(new Image(hudAtlas.findRegion(TIME_REGION))).padRight(12.0f);
	status.add(timeLabel).row();
	status.setFillParent(true);
	status.top();
	status.pad(15.0f);
	stage.addActor(status);

	Table levelInfo = new Table();
	levelInfo.add(new Label(LEVEL_LABEL, style)).expandX().right().padRight(18.0f);
	levelInfo.add(new Label(String.format(LEVEL_FORMAT, playerStatus.getWorld(), playerStatus.getLevel()), style)).expandX()
			.left().padTop(18.0f).row();
	Image livesIcon = new Image(hudAtlas.findRegion(LIVES_REGION));
	levelInfo.add(livesIcon).expandX().right().spaceRight(25f);
	levelInfo.add(livesLabel).expandX().left().bottom();
	levelInfo.setFillParent(true);
	stage.addActor(levelInfo);

}
 
Example #19
Source File: GameOverOverlay.java    From ninja-rabbit with GNU General Public License v2.0 5 votes vote down vote up
public GameOverOverlay(final Batch batch, final AssetManager assets) {
	stage = new Stage(new ScreenViewport(), batch);
	Label.LabelStyle style = new Label.LabelStyle();
	style.fontColor = Color.WHITE;
	style.font = assets.get(Assets.HUD_FONT);
	Label gameOver = new Label(GAME_OVER_TEXT, style);

	Table table = new Table();
	table.setFillParent(true);
	table.add(gameOver).expand();

	stage.addActor(table);
	overlay = new ShapeRenderer();

}
 
Example #20
Source File: BehaviorTreeTests.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
public MainScreen() {
	Gdx.gl.glClearColor(.3f, .3f, .3f, 1);

	skin = new Skin(Gdx.files.internal("data/uiskin.json"));

	stage = new Stage(new ScreenViewport());
	stage.setDebugAll(DEBUG_STAGE);

	// Create split pane
	List<String> testList = createTestList();
	ScrollPane leftScrollPane = new ScrollPane(testList, skin);
	splitPane = new SplitPane(leftScrollPane, null, false, skin, "default-horizontal");
	splitPane.setSplitAmount(Math.min((testList.getPrefWidth() + 10) / stage.getWidth(), splitPane.getSplitAmount()));

	// Create layout
	Table t = new Table(skin);
	t.setFillParent(true);
	t.add(splitPane).colspan(3).grow();
	t.row();
	t.add(pauseButton = new PauseButton(skin)).width(90).left();
	t.add(new FpsLabel("FPS: ", skin)).left();
	t.add(testDescriptionLabel = new Label("", skin)).left();
	stage.addActor(t);

	// Set selected test
	changeTest(0);
}
 
Example #21
Source File: CardDeckApplication.java    From androidsvgdrawable-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void create () {
    manager = new AssetManager();
    manager.load("skin.json", Skin.class);
    manager.load("skin.atlas", TextureAtlas.class);
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
}
 
Example #22
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 #23
Source File: PauseMenuUI.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void initVariables(Camera camera) {
	stage = new Stage(new ScreenViewport(camera));
	menuTable = new Table();
	menuTable.setDebug(false);
	menuTable.setFillParent(true);
	this.setVisible(false);
}
 
Example #24
Source File: PlayerBattleHUD.java    From Norii with Apache License 2.0 5 votes vote down vote up
private void initVariables(Camera camera, Entity[] sortedUnits) {
	statusUIs = new StatusUI[sortedUnits.length];
	actionUIs = new ActionsUI[Player.getInstance().getUnitsSortedByIni().length];
	hpBars = new HPBar[sortedUnits.length];
	stage = new Stage(new ScreenViewport(camera));
	stage.setDebugAll(false);
}
 
Example #25
Source File: DialogSceneComposerJavaBuilder.java    From skin-composer with MIT License 5 votes vote down vote up
private static MethodSpec createMethod() {
    return MethodSpec.methodBuilder("create")
            .addModifiers(Modifier.PUBLIC)
            .addStatement("stage = new $T(new $T())", Stage.class, ScreenViewport.class)
            .addStatement("skin = new $T($T.files.internal($S))", Skin.class, Gdx.class, rootActor.skinPath)
            .addStatement("$T.input.setInputProcessor(stage)", Gdx.class)
            .addCode(createWidget(rootActor, new Array<>(), new ObjectSet<>()).codeBlock)
            .returns(void.class).build();
}
 
Example #26
Source File: Main.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public void create() {
    appFolder = Gdx.files.external(".skincomposer/");
    
    skin = new FreeTypeSkin(Gdx.files.internal("skin-composer-ui/skin-composer-ui.json"));
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
    
    shapeDrawer = new ShapeDrawer(stage.getBatch(), skin.getRegion("white"));
    graphDrawer = new GraphDrawer(shapeDrawer);
    
    initDefaults();
    
    populate();
}
 
Example #27
Source File: ViewportService.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Initiate(priority = VERY_HIGH_PRIORITY) void init() {
    prefs = Gdx.app.getPreferences(AppConstants.PREF_NAME_COMMON);
    scale = prefs.getFloat(PREF_KEY_UI_SCALE, scale);

    viewport = new ScreenViewport();
    viewport.setUnitsPerPixel(scale);
}
 
Example #28
Source File: MyScreen.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void show() {
    batch = new SpriteBatch();
    font = new BitmapFont();
    font.getData().setScale(2);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    viewport = new ScreenViewport();
}
 
Example #29
Source File: MyGame.java    From ud405 with MIT License 5 votes vote down vote up
@Override
public void create() {
    batch = new SpriteBatch();
    font = new BitmapFont();
    font.getData().setScale(2);
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    viewport = new ScreenViewport();
}
 
Example #30
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;

}