I have created some buttons in LibGDX and drew them on the screen, but the detection for the mouse clicks is off-centered on them. The mouse click seems to register halfway above the the button, and another half past it. Here's a diagram of what I believe is happening.
So how would I go about fixing this?
*Edit
Oops, forgot to put code.
package com.sael.logic;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
public class MenuScreen implements Screen {
private Texture MainMenuTexture;
private SpriteBatch batch;
private Stage stage;
private TextButton buttonPlay, buttonStore;
private TextureAtlas buttonAtlas;
private BitmapFont font;
private Skin skin;
private TextButtonStyle style;
@Override
public void render(float delta) {
batch.begin();
batch.draw(MainMenuTexture, 0, 0);
batch.end();
stage.act();
stage.draw();
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
MainMenuTexture = new Texture(Gdx.files.internal("data/Graphics/MainMenuBack.png"));
batch = new SpriteBatch();
stage = new Stage(480, 800, true);
font = new BitmapFont();
skin = new Skin();
buttonAtlas = new TextureAtlas(Gdx.files.internal("data/Graphics/Buttons.atlas"));
Gdx.input.setInputProcessor(stage);
skin.addRegions(buttonAtlas);
style = new TextButtonStyle();
style.font = font;
style.up = skin.getDrawable("Button_Up");
style.down = skin.getDrawable("Button_Down");
buttonPlay = new TextButton("PLAY", style);
buttonPlay.setPosition(480 /2 - 200 /2, 400);
buttonPlay.setWidth(200);
buttonPlay.setHeight(60);
buttonStore = new TextButton("STORE", style);
buttonStore.setPosition(480 / 2 - 200/2, 300);
buttonStore.setWidth(200);
buttonStore.setHeight(60);
stage.addActor(buttonPlay);
stage.addActor(buttonStore);
}