Hi all,
I am starting to do my first steps with libgdx and got realy fast first problems
my button eventlistener will not work. Here is my class.
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import java.awt.event.InputEvent;
public class MyGdxGame_test2 extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
private TextButton exitButton;
private Stage stage;
private BitmapFont font;
@Override
public void create () {
stage= new Stage();
Gdx.input.setInputProcessor(stage);
batch = new SpriteBatch();
img = new Texture("textures/title.png");
TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle();
buttonStyle.fontColor = Color.BLACK;
font = new BitmapFont(Gdx.files.internal("fonts/plaincred.fnt"),false);
buttonStyle.font =font;
exitButton = new TextButton("Exit", buttonStyle);
exitButton.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("X:" + x + " Y:" + y);
//return true;
}
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("X:" + x + " Y:" + y);
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
System.out.println("touchup");
}
});
stage.addActor(exitButton);
System.out.println("Start");
}
@Override
public void render () {
float t = Gdx.graphics.getDeltaTime();
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0, stage.getWidth(), stage.getHeight());
batch.end();
stage.act(t);
stage.draw();
}
}
I was serching at the web, but i dont know what i have to change.
I setted the InputProcessor, I added the clicklistener, tried touchdown, up and click events but nothing helpes.
is there anything else I have to configure or start? maybe on the android class part or manifest?
Please help.