use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.
the class ViewportTest1 method getViewports.
public static Array<Viewport> getViewports(Camera camera) {
int minWorldWidth = 640;
int minWorldHeight = 480;
int maxWorldWidth = 800;
int maxWorldHeight = 480;
Array<Viewport> viewports = new Array();
viewports.add(new StretchViewport(minWorldWidth, minWorldHeight, camera));
viewports.add(new FillViewport(minWorldWidth, minWorldHeight, camera));
viewports.add(new FitViewport(minWorldWidth, minWorldHeight, camera));
viewports.add(new ExtendViewport(minWorldWidth, minWorldHeight, camera));
viewports.add(new ExtendViewport(minWorldWidth, minWorldHeight, maxWorldWidth, maxWorldHeight, camera));
viewports.add(new ScreenViewport(camera));
ScreenViewport screenViewport = new ScreenViewport(camera);
screenViewport.setUnitsPerPixel(0.75f);
viewports.add(screenViewport);
viewports.add(new ScalingViewport(Scaling.none, minWorldWidth, minWorldHeight, camera));
return viewports;
}
use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.
the class ViewportTest2 method render.
public void render() {
batch.setProjectionMatrix(camera.projection);
batch.setTransformMatrix(camera.view);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
// draw a white background so we are able to see the black bars
batch.setColor(1, 1, 1, 1);
batch.draw(texture, -4096, -4096, 4096, 4096, 8192, 8192, 1, 1, 0, 0, 0, 16, 16, false, false);
batch.setColor(1, 0, 0, 1);
batch.draw(texture, 150, 100, 16, 16, 32, 32, 1, 1, 45, 0, 0, 16, 16, false, false);
font.draw(batch, viewport.getClass().getSimpleName(), 150, 100);
batch.end();
if (viewport instanceof ScalingViewport) {
// This shows how to set the viewport to the whole screen and draw within the black bars.
ScalingViewport scalingViewport = (ScalingViewport) viewport;
int screenWidth = Gdx.graphics.getWidth();
int screenHeight = Gdx.graphics.getHeight();
HdpiUtils.glViewport(0, 0, screenWidth, screenHeight);
batch.getProjectionMatrix().idt().setToOrtho2D(0, 0, screenWidth, screenHeight);
batch.getTransformMatrix().idt();
batch.begin();
float leftGutterWidth = scalingViewport.getLeftGutterWidth();
if (leftGutterWidth > 0) {
batch.draw(texture, 0, 0, leftGutterWidth, screenHeight);
batch.draw(texture, scalingViewport.getRightGutterX(), 0, scalingViewport.getRightGutterWidth(), screenHeight);
}
float bottomGutterHeight = scalingViewport.getBottomGutterHeight();
if (bottomGutterHeight > 0) {
batch.draw(texture, 0, 0, screenWidth, bottomGutterHeight);
batch.draw(texture, 0, scalingViewport.getTopGutterY(), screenWidth, scalingViewport.getTopGutterHeight());
}
batch.end();
// Restore viewport.
viewport.update(screenWidth, screenHeight, true);
}
}
use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.
the class BaseG3dHudTest method createHUD.
protected void createHUD() {
hud = new Stage(new ScalingViewport(Scaling.fit, PREF_HUDWIDTH, PREF_HUDHEIGHT));
hudWidth = hud.getWidth();
hudHeight = hud.getHeight();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
final List<String> modelsList = new List(skin);
modelsList.setItems(models);
modelsList.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (!modelsWindow.isCollapsed() && getTapCount() == 2) {
onModelClicked(modelsList.getSelected());
modelsWindow.collapse();
}
}
});
modelsWindow = addListWindow("Models", modelsList, 0, -1);
fpsLabel = new Label("FPS: 999", skin);
hud.addActor(fpsLabel);
gridCheckBox = new CheckBox("Show grid", skin);
gridCheckBox.setChecked(showAxes);
gridCheckBox.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showAxes = gridCheckBox.isChecked();
}
});
gridCheckBox.setPosition(hudWidth - gridCheckBox.getWidth(), 0);
hud.addActor(gridCheckBox);
rotateCheckBox = new CheckBox("Rotate", skin);
rotateCheckBox.setChecked(true);
rotateCheckBox.setPosition(hudWidth - rotateCheckBox.getWidth(), gridCheckBox.getHeight());
hud.addActor(rotateCheckBox);
moveCheckBox = new CheckBox("Move", skin);
moveCheckBox.setChecked(false);
moveCheckBox.setPosition(hudWidth - moveCheckBox.getWidth(), rotateCheckBox.getTop());
hud.addActor(moveCheckBox);
}
use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.
the class StagePerformanceTest method create.
@Override
public void create() {
batch = new SpriteBatch();
font = new BitmapFont();
stage = new Stage(new ScalingViewport(Scaling.fit, 24, 12));
regions = new TextureRegion[8 * 8];
sprites = new Sprite[24 * 12];
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
regions[x + y * 8] = new TextureRegion(texture, x * 32, y * 32, 32, 32);
}
}
Random rand = new Random();
for (int y = 0, i = 0; y < 12; y++) {
for (int x = 0; x < 24; x++) {
Image img = new Image(regions[rand.nextInt(8 * 8)]);
img.setBounds(x, y, 1, 1);
stage.addActor(img);
sprites[i] = new Sprite(regions[rand.nextInt(8 * 8)]);
sprites[i].setPosition(x, y);
sprites[i].setSize(1, 1);
i++;
}
}
}
Aggregations