use of com.badlogic.gdx.scenes.scene2d.Stage 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.scenes.scene2d.Stage 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();
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class MusicTest method create.
@Override
public void create() {
music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
music.play();
buttons = new TextureRegion(new Texture(Gdx.files.internal("data/playback.png")));
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
slider = new Slider(0, 100, 0.1f, false, skin);
slider.setPosition(200, 20);
slider.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (!sliderUpdating && slider.isDragging())
music.setPosition((slider.getValue() / 100f) * songDuration);
}
});
stage.addActor(slider);
Gdx.input.setInputProcessor(stage);
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class SimpleStageCullingTest method create.
@Override
public void create() {
// create a stage and a camera controller so we can pan the view.
stage = new Stage();
;
// we know it's an ortho cam at this point!
camController = new OrthoCamController((OrthographicCamera) stage.getCamera());
Gdx.input.setInputProcessor(camController);
// load a dummy texture
texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
// populate the stage with some actors and groups.
for (int i = 0; i < 5000; i++) {
Actor img = new CullableActor("img" + i, texture, (OrthographicCamera) stage.getCamera());
img.setX((float) Math.random() * 480 * 10);
img.setY((float) Math.random() * 320 * 10);
stage.addActor(img);
}
// we also want to output the number of visible actors, so we need a SpriteBatch and a BitmapFont
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class SoundTest method create.
@Override
public void create() {
sound = Gdx.audio.newSound(Gdx.files.getFileHandle("data/shotgun.ogg", FileType.Internal));
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
ui = new Stage();
TextButton play = new TextButton("Play", skin);
TextButton stop = new TextButton("Stop", skin);
final Slider pitch = new Slider(0.1f, 4, 0.1f, false, skin);
pitch.setValue(1);
final Label pitchValue = new Label("1.0", skin);
final Slider volume = new Slider(0.1f, 1, 0.1f, false, skin);
volume.setValue(1);
final Label volumeValue = new Label("1.0", skin);
Table table = new Table();
final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
pan.setValue(0);
final Label panValue = new Label("0.0", skin);
table.setFillParent(true);
table.align(Align.center | Align.top);
table.columnDefaults(0).expandX().right().uniformX();
table.columnDefaults(2).expandX().left().uniformX();
table.add(play);
table.add(stop).left();
table.row();
table.add(new Label("Pitch", skin));
table.add(pitch);
table.add(pitchValue);
table.row();
table.add(new Label("Volume", skin));
table.add(volume);
table.add(volumeValue);
table.row();
table.add(new Label("Pan", skin));
table.add(pan);
table.add(panValue);
ui.addActor(table);
play.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
soundId = sound.play(volume.getValue());
sound.setPitch(soundId, pitch.getValue());
sound.setPan(soundId, pan.getValue(), volume.getValue());
}
});
stop.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
sound.stop(soundId);
}
});
pitch.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
sound.setPitch(soundId, pitch.getValue());
pitchValue.setText("" + pitch.getValue());
}
});
volume.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
sound.setVolume(soundId, volume.getValue());
volumeValue.setText("" + volume.getValue());
}
});
pan.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
sound.setPan(soundId, pan.getValue(), volume.getValue());
panValue.setText("" + pan.getValue());
}
});
Gdx.input.setInputProcessor(ui);
}
Aggregations