use of com.badlogic.gdx.scenes.scene2d.InputEvent in project libgdx by libgdx.
the class TreeTest method create.
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
Table table = new Table();
table.setFillParent(true);
stage.addActor(table);
final Tree tree = new Tree(skin);
final Node moo1 = new Node(new TextButton("moo1", skin));
final Node moo2 = new Node(new TextButton("moo2", skin));
final Node moo3 = new Node(new TextButton("moo3", skin));
final Node moo4 = new Node(new TextButton("moo4", skin));
final Node moo5 = new Node(new TextButton("moo5", skin));
tree.add(moo1);
tree.add(moo2);
moo2.add(moo3);
moo3.add(moo4);
tree.add(moo5);
moo5.getActor().addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
tree.remove(moo4);
}
});
table.add(tree).fill().expand();
}
use of com.badlogic.gdx.scenes.scene2d.InputEvent 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.InputEvent 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.InputEvent in project Entitas-Java by Rubentxu.
the class GuiFactory method createPadButtons.
public Table createPadButtons(float width, float height, InputEntity player) {
Table tableControlPad = new Table();
PlayerInputController stateController = player.getPlayerInputController();
tableControlPad.row().height(height);
ImageButton btnLeft = new ImageButton(skin, "buttonLeft");
tableControlPad.add(btnLeft).width(width).expandY().fill();
btnLeft.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchDown(event, x, y, pointer, button);
// controller.leftPressed();
// controller.rightReleased();
player.replacePlayerInputController(true, false, stateController.jumpPressed);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchUp(event, x, y, pointer, button);
// controller.leftReleased();
player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
System.out.println("Event- " + event.getType());
super.touchDragged(event, x, y, pointer);
if (isOver(event.getListenerActor(), x, y)) {
// controller.rightReleased();
// controller.leftPressed();
player.replacePlayerInputController(true, false, stateController.jumpPressed);
} else {
// controller.leftReleased();
player.replacePlayerInputController(false, stateController.rightPressed, stateController.jumpPressed);
}
}
});
ImageButton btnRight = new ImageButton(skin, "buttonRight");
tableControlPad.add(btnRight).width(width).expandY().fill().padRight((width) * 2);
btnRight.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchDown(event, x, y, pointer, button);
// controller.leftReleased();
// controller.rightPressed();
player.replacePlayerInputController(false, true, stateController.jumpPressed);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchUp(event, x, y, pointer, button);
// controller.rightReleased();
player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
System.out.println("Event- " + event.getType());
super.touchDragged(event, x, y, pointer);
if (isOver(event.getListenerActor(), x, y)) {
// controller.rightPressed();
// controller.leftReleased();
player.replacePlayerInputController(false, true, stateController.jumpPressed);
} else {
// controller.rightReleased();
player.replacePlayerInputController(stateController.leftPressed, false, stateController.jumpPressed);
}
}
});
ImageButton btnUP = new ImageButton(skin, "buttonUp");
tableControlPad.add(btnUP).width(width).expandY().fill();
btnUP.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchDown(event, x, y, pointer, button);
// controller.jumpPressed();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("Event " + event.getType());
super.touchUp(event, x, y, pointer, button);
// controller.jumpReleased();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer) {
System.out.println("Event- " + event.getType());
super.touchDragged(event, x, y, pointer);
if (isOver(event.getListenerActor(), x, y)) {
// controller.jumpPressed();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
} else {
// controller.jumpReleased();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
}
}
});
tableControlPad.setBounds(0, 0, Gdx.graphics.getWidth(), height + 10);
return tableControlPad;
}
use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Entitas-Java by Rubentxu.
the class MenuState method init.
@Override
public void init() {
Gdx.app.log("Menu", "Init");
int pad = (int) (20 * SMGUIManager.ScaleUtil.getSizeRatio());
int pad2 = (int) (60 * SMGUIManager.ScaleUtil.getSizeRatio());
final TextButton btnStart = new TextButton("Comenzar", skin);
btnStart.pad(pad, pad2, pad, pad2);
final TextButton btnOptions = new TextButton("Opciones", skin);
btnOptions.pad(pad, pad2, pad, pad2);
final TextButton btnScores = new TextButton("Puntuaciones", skin);
btnScores.pad(pad, pad2, pad, pad2);
final TextButton button3 = new TextButton("Creditos", skin);
button3.pad(pad, pad2, pad, pad2);
button3.setChecked(false);
btnStart.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click Comenzar...");
}
});
btnOptions.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click optionScreen...");
SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getOptionState(), game.getFadeTransition()));
}
});
btnScores.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click highScoreScreen...");
SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getScoresState(), game.getSlideTransition()));
}
});
Label label = new Label("SUPER MARIANO", skin, "header", Color.CYAN);
label.setAlignment(Align.center, Align.center);
mainTable.defaults().padBottom(pad);
if (Gdx.graphics.getHeight() < 480)
mainTable.defaults().height(Gdx.graphics.getHeight() / 5f - pad);
mainTable.add(label);
mainTable.row();
mainTable.add(btnStart);
mainTable.row();
mainTable.add(btnOptions);
mainTable.row();
mainTable.add(btnScores);
mainTable.row();
mainTable.add(button3);
mainTable.row();
mainTable.setBackground(new SpriteDrawable(new Sprite((Texture) assetsManager.getTexture(SMGUIManager.MENU_BACKGROUND))));
mainTable.row();
}
Aggregations