use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class StageDebugTest method create.
@Override
public void create() {
textureRegion = new TextureRegion(new Texture("data/badlogic.jpg"));
Gdx.input.setInputProcessor(this);
stage1 = new Stage();
stage1.getCamera().position.set(100, 100, 0);
Group group = new Group();
// group.setBounds(0, 0, 10, 10);
// group.setOrigin(25, 50);
group.setRotation(10);
group.setScale(1.2f);
stage1.addActor(group);
DebugActor actor = new DebugActor();
actor.setBounds(300, 140, 50, 100);
actor.setOrigin(25, 50);
actor.setRotation(-45);
actor.setScale(2f);
actor.addAction(forever(rotateBy(360, 8f)));
group.addActor(actor);
group.debugAll();
stage2 = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
TextButton shortButton = new TextButton("Button short", skin);
shortButton.debug();
TextButton longButton = new TextButton("Button loooooooooong", skin);
longButton.debug();
Table root = new Table(skin);
root.setFillParent(true);
root.setBackground(skin.getDrawable("default-pane"));
root.defaults().space(6);
root.setTransform(true);
root.rotateBy(10);
root.setScale(1.3f, 1);
root.debug();
stage2.addActor(root);
root.add(shortButton).pad(5);
root.add(longButton).row();
root.add("Colspan").colspan(2).row();
switchStage();
}
use of com.badlogic.gdx.scenes.scene2d.Stage 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++;
}
}
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class TableLayoutTest method create.
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Label nameLabel = new Label("Name:", skin);
TextField nameText = new TextField("", skin);
Label addressLabel = new Label("Address:", skin);
TextField addressText = new TextField("", skin);
Table table = new Table();
stage.addActor(table);
table.setSize(260, 195);
table.setPosition(190, 142);
// table.align(Align.right | Align.bottom);
table.debug();
TextureRegion upRegion = skin.getRegion("default-slider-knob");
TextureRegion downRegion = skin.getRegion("default-slider-knob");
BitmapFont buttonFont = skin.getFont("default-font");
TextButton button = new TextButton("Button 1", skin);
button.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("touchDown 1");
return false;
}
});
table.add(button);
// table.setTouchable(Touchable.disabled);
Table table2 = new Table();
stage.addActor(table2);
table2.setFillParent(true);
table2.bottom();
TextButton button2 = new TextButton("Button 2", skin);
button2.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
System.out.println("2!");
}
});
button2.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("touchDown 2");
return false;
}
});
table2.add(button2);
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class TableTest method create.
@Override
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
TextureRegion region = new TextureRegion(texture);
NinePatch patch = skin.getPatch("default-round");
Label label = new Label("This is some text.", skin);
root = new Table() {
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
}
};
stage.addActor(root);
// root.setTransform(true);
Table table = new Table();
table.setTransform(true);
table.setPosition(100, 100);
table.setOrigin(0, 0);
table.setRotation(45);
table.setScaleY(2);
table.add(label);
table.add(new TextButton("Text Button", skin));
table.pack();
// table.debug();
table.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("click!");
}
});
// root.addActor(table);
TextButton button = new TextButton("Text Button", skin);
Table table2 = new Table();
// table2.debug()
table2.add(button);
table2.setTransform(true);
table2.setScaleX(1.5f);
table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
// Test colspan with expandX.
// root.setPosition(10, 10);
root.debug();
root.setFillParent(true);
root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
root.add(new TextButton("Text Button", skin));
root.row();
root.add(new TextButton("Text Button", skin));
root.add(new TextButton("Toggle Button", skin.get("toggle", TextButtonStyle.class)));
root.add(new CheckBox("meow meow meow meow meow meow meow meow", skin));
// root.pack();
// root.add(new Button(new Image(region), skin));
// root.add(new LabelButton("Toggley", skin.getStyle("toggle", LabelButtonStyle.class)));
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class YDownTest method create.
@Override
public void create() {
// a bitmap font to draw some text, note that we
// pass true to the constructor, which flips glyphs on y
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true);
// a texture region, note the flipping on y again
region = new TextureRegion(new Texture("data/badlogic.jpg"));
region.flip(false, true);
// a texture atlas, note the boolean
atlas = new TextureAtlas(Gdx.files.internal("data/pack"), true);
// a sprite, created from a region in the atlas
sprite = atlas.createSprite("badlogicsmall");
sprite.setPosition(0, 0);
// a sprite batch with which we want to render
batch = new SpriteBatch();
// a camera, note the setToOrtho call, which will set the y-axis
// to point downwards
camera = new OrthographicCamera();
camera.setToOrtho(true);
// a stage which uses our y-down camera and a simple actor (see MyActor below),
// which uses the flipped region. The key here is to
// set our y-down camera on the stage, the rest is just for demo purposes.
stage = new Stage();
stage.getViewport().setCamera(camera);
image = new MyActor(region);
image.setPosition(100, 100);
stage.addActor(image);
// finally we write up the stage as the input process and call it a day.
Gdx.input.setInputProcessor(stage);
}
Aggregations