Stefan
Stefan

Reputation: 1895

Libgdx Click for x, y coordinates

I got a moving square wich moves around in my window and this works fine. But when I try to use public void clicked from libgdx I can't get it to work. This is how my void looks like:

public void clicked(InputEvent event,float x,float y){
    rect.y = y;
    rect.x = x;
}

Above this im also adding the movement from the box and this works fine so its not rect.y and rect.x. Why aren't rect.y and rect.x changing to the float x and float y from my void when Clicked?

Libgdx Void:

http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/utils/ClickListener.html#clicked-com.badlogic.gdx.scenes.scene2d.InputEvent-float-float-

Why isn't this working?

Thanks for reading/helping!

Upvotes: 0

Views: 824

Answers (1)

Malik Brahimi
Malik Brahimi

Reputation: 16711

Put this in your game's render method:

if(Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
    rect.x = Gdx.input.getX();
    rect.y = Gdx.input.getY();
}

rect must be defined within your game's class.

Upvotes: 1

Related Questions