public class Game2 extends ApplicationAdapter {
private SpriteBatch batch;
private WidgetFactory widgetFactory;
private TextButton moveButton;
private Rectangle textureRect = new Rectangle();
batch = new SpriteBatch();
widgetFactory = new WidgetFactory();
Gdx.input.setInputProcessor(stage);
widgetFactory.prepareSkin();
texture = new Texture("badlogic.jpg");
textureRect.height = 100;
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
private void setupViews() {
Table table = new Table();
table.setFillParent(true);
moveButton = widgetFactory.getButton("Вперед");
moveButton.addListener(new InputListener() {
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
textureRect.y = textureRect.y + 10;
textureRect.x = textureRect.x + 10;
class WidgetFactory extends ApplicationAdapter {
public void prepareSkin() {
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.WHITE);
skin.add("white", new Texture(pixmap));
skin.add("default", new BitmapFont());
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);
public TextButton getButton(String text) {
TextButton button = new TextButton(text, skin);
button.getLabel().setFontScale(2);