use of com.badlogic.gdx.utils.viewport.ScreenViewport 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.ScreenViewport in project libgdx by libgdx.
the class GroupTest method create.
public void create() {
batch = new SpriteBatch();
font = new BitmapFont();
renderer = new ShapeRenderer();
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);
region = new TextureRegion(new Texture(Gdx.files.internal("data/group-debug.png")));
group2 = new TestGroup("group2");
group2.setTransform(true);
stage.addActor(group2);
group1 = new TestGroup("group1");
group1.setTransform(true);
group2.addActor(group1);
LabelStyle style = new LabelStyle();
style.font = new BitmapFont();
Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
horiz = new HorizontalGroup().pad(10, 20, 30, 40).top().space(5).reverse();
for (int i = 1; i <= 15; i++) {
horiz.addActor(new Label(i + ",", style));
if (i == 7)
horiz.addActor(new Container(new Image(texture)).size(10));
}
horiz.addActor(new Container(new Image(texture)).fill().prefSize(30));
horiz.debug();
horiz.setPosition(10, 10);
horiz.pack();
stage.addActor(horiz);
horizWrap = new HorizontalGroup().wrap().pad(10, 20, 30, 40).right().rowBottom().space(5).wrapSpace(15).reverse();
for (int i = 1; i <= 15; i++) {
horizWrap.addActor(new Label(i + ",", style));
if (i == 7)
horizWrap.addActor(new Container(new Image(texture)).prefSize(10).fill());
}
horizWrap.addActor(new Container(new Image(texture)).prefSize(30));
horizWrap.debug();
horizWrap.setBounds(10, 85, 150, 40);
stage.addActor(horizWrap);
vert = new VerticalGroup().pad(10, 20, 30, 40).top().space(5).reverse();
for (int i = 1; i <= 8; i++) {
vert.addActor(new Label(i + ",", style));
if (i == 4)
vert.addActor(new Container(new Image(texture)).size(10));
}
vert.addActor(new Container(new Image(texture)).size(30));
vert.debug();
vert.setPosition(515, 10);
vert.pack();
stage.addActor(vert);
vertWrap = new VerticalGroup().wrap().pad(10, 20, 30, 40).bottom().columnRight().space(5).wrapSpace(15).reverse();
for (int i = 1; i <= 8; i++) {
vertWrap.addActor(new Label(i + ",", style));
if (i == 4)
vertWrap.addActor(new Container(new Image(texture)).prefSize(10).fill());
}
vertWrap.addActor(new Container(new Image(texture)).prefSize(30));
vertWrap.debug();
vertWrap.setBounds(610, 10, 150, 40);
stage.addActor(vertWrap);
}
use of com.badlogic.gdx.utils.viewport.ScreenViewport in project libgdx by libgdx.
the class InterpolationTest method create.
@Override
public void create() {
Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
renderer = new ShapeRenderer();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
stage = new Stage(new ScreenViewport());
resetPositions();
Field[] interpolationFields = ClassReflection.getFields(Interpolation.class);
// see how many fields are actually interpolations (for safety; other fields may be added with future)
int interpolationMembers = 0;
for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
interpolationMembers++;
// get interpolation names
interpolationNames = new String[interpolationMembers];
for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
interpolationNames[i] = interpolationFields[i].getName();
selectedInterpolation = interpolationNames[0];
list = new List(skin);
list.setItems(interpolationNames);
list.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
selectedInterpolation = list.getSelected();
time = 0;
resetPositions();
}
});
ScrollPane scroll = new ScrollPane(list, skin);
scroll.setFadeScrollBars(false);
scroll.setScrollingDisabled(true, false);
table = new Table();
table.setFillParent(true);
table.add(scroll).expandX().left().width(100);
stage.addActor(table);
Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
public boolean scrolled(int amount) {
if (!Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
return false;
duration -= amount / 15f;
duration = MathUtils.clamp(duration, 0, Float.POSITIVE_INFINITY);
return true;
}
}, stage, new InputAdapter() {
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (// if "walking" was interrupted by this touch down event
!Float.isNaN(time))
// set startPosition to the current position
startPosition.set(getPosition(time));
targetPosition.set(stage.screenToStageCoordinates(targetPosition.set(screenX, screenY)));
time = 0;
return true;
}
}));
}
use of com.badlogic.gdx.utils.viewport.ScreenViewport in project libgdx by libgdx.
the class StageTest method create.
@Override
public void create() {
texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
stage = new Stage(new ScreenViewport());
float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2;
for (int i = 0; i < NUM_GROUPS; i++) {
Group group = new Group();
group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
group.setOrigin(loc, loc);
fillGroup(group, texture);
stage.addActor(group);
}
uiTexture = new Texture(Gdx.files.internal("data/ui.png"));
uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
ui = new Stage(new ScreenViewport());
Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
blend.setAlign(Align.center);
blend.setScaling(Scaling.none);
blend.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (stage.getBatch().isBlendingEnabled())
stage.getBatch().disableBlending();
else
stage.getBatch().enableBlending();
return true;
}
});
blend.setY(ui.getHeight() - 64);
Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
rotate.setAlign(Align.center);
rotate.setScaling(Scaling.none);
rotate.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
rotateSprites = !rotateSprites;
return true;
}
});
rotate.setPosition(64, blend.getY());
Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
scale.setAlign(Align.center);
scale.setScaling(Scaling.none);
scale.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
scaleSprites = !scaleSprites;
return true;
}
});
scale.setPosition(128, blend.getY());
{
Actor shapeActor = new Actor() {
public void drawDebug(ShapeRenderer shapes) {
shapes.set(ShapeType.Filled);
shapes.setColor(getColor());
shapes.rect(getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
};
shapeActor.setBounds(0, 0, 100, 150);
shapeActor.setOrigin(50, 75);
shapeActor.debug();
sprites.add(shapeActor);
Group shapeGroup = new Group();
shapeGroup.setBounds(300, 300, 300, 300);
shapeGroup.setOrigin(50, 75);
shapeGroup.setTouchable(Touchable.childrenOnly);
shapeGroup.addActor(shapeActor);
stage.addActor(shapeGroup);
}
ui.addActor(blend);
ui.addActor(rotate);
ui.addActor(scale);
fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
fps.setPosition(10, 30);
fps.setColor(0, 1, 0, 1);
ui.addActor(fps);
renderer = new ShapeRenderer();
Gdx.input.setInputProcessor(this);
}
use of com.badlogic.gdx.utils.viewport.ScreenViewport in project libgdx by libgdx.
the class TextAreaScrollTest method create.
@Override
public void create() {
stage = new Stage(new ScreenViewport());
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Gdx.input.setInputProcessor(stage);
Table container = new Table();
stage.addActor(container);
container.setFillParent(true);
container.pad(10).defaults().expandX().fillX().space(4);
textArea = new TextArea(">>> FIRST LINE <<<\n" + "Scrolling to the bottom of the area you should see the last line.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n" + "Scrolling to the top of the area you should see the first line.\n" + ">>> LAST LINE <<<", skin) {
public float getPrefHeight() {
return getLines() * getStyle().font.getLineHeight();
}
};
scrollPane = new ScrollPane(textArea, skin);
scrollPane.setFadeScrollBars(false);
scrollPane.setFlickScroll(false);
container.row().height(350);
container.add(scrollPane);
container.debugAll();
}
Aggregations