Scene2d Window now detecting move

Anything libgdx related goes here!

Scene2d Window now detecting move

Postby gamedev101 » Wed Jan 29, 2020 6:37 pm

Hi,
I'm using a Scene2d Window and when clicking on title bar of it and then trying to move it via mouse it doesn't move most of the time. Sometimes depending on where
you click on the title it grabs the window and allows you to move it. I am using a WindowStyle to add a bitmap to the window and believe this is possibly causing the issue but I'm not sure?

Code as follows (I've ommitted the override methods to keep it small)

Code: Select all
public class QuestWindow extends ApplicationAdapter implements InputProcessor {
    private Stage stage;
    private WindowWithTopRightCornerCloseButton windowWithTopRightCornerCloseButton;

    public QuestWindow() {
        create();
    }

    public void create() {
        stage = new Stage();
        windowWithTopRightCornerCloseButton = new WindowWithTopRightCornerCloseButton();
        windowWithTopRightCornerCloseButton.setSize(600, 600);
        windowWithTopRightCornerCloseButton.setModal(true);
        windowWithTopRightCornerCloseButton.setVisible(true);
        windowWithTopRightCornerCloseButton.setMovable(true);
        windowWithTopRightCornerCloseButton.setPosition(Gdx.graphics.getWidth()/2 - windowWithTopRightCornerCloseButton.getWidth()/2, Gdx.graphics.getHeight()/2 - windowWithTopRightCornerCloseButton.getHeight()/2);
        stage.addActor(windowWithTopRightCornerCloseButton);
        InputMultiplexer multiplexer = new InputMultiplexer(this);
        multiplexer.addProcessor(this);
        multiplexer.addProcessor(stage);
        Gdx.input.setInputProcessor(multiplexer);
    }
    @Override
    public void dispose() {
        stage.dispose();
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.draw();
        stage.act();     
    }
}


And the window class itself:

Code: Select all
public class WindowWithTopRightCornerCloseButton extends Window {

    private static final WindowStyle windowStyle;
    private static final ImageButtonStyle closeButtonStyle;

    static {
        TextureAtlas textureAtlas = new TextureAtlas(Gdx.files.absolute(IFileName.HUDroot + "/windows.pack"));
        windowStyle = new WindowStyle(new BitmapFont(), Color.BLACK, new TextureRegionDrawable(textureAtlas.findRegion("window-1-background")));
        closeButtonStyle = new ImageButtonStyle();
        closeButtonStyle.imageUp = new TextureRegionDrawable(textureAtlas.findRegion("window-1-close-button"));
    }

    public WindowWithTopRightCornerCloseButton() {
        super("", windowStyle);
        setMovable(true);
        getTitleTable().setDebug(true);
        getTitleTable().add(closeButton).size(38, 38).padRight(20).padTop(20);
        setClip(true);
        setTransform(true);
    }
}


I'm not really sure why this is happening, the code I found on the internet and looks ok to me. I just want to be able to put a bitmap over the scene2d window.

Any help is much appreciated.

Thanks
gamedev101
 
Posts: 13
Joined: Thu Nov 28, 2019 7:43 pm

Re: Scene2d Window now detecting move

Postby shatterblast » Wed Jan 29, 2020 10:26 pm

You might try putting your Button in a Container, and then, add the Container to the Window itself in case of any conflicts.
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Scene2d Window now detecting move

Postby gamedev101 » Thu Jan 30, 2020 8:27 am

The close button listener actually does work but only for one of the windows - I did try use an inputmultiplexer but the same. Its just moving the window around doesn't, it is as though checking when clicked in the caption bar isn't being detected correctly, you can click along the caption bar and sometimes it does get captured but then move the window and the position of where click detection is will then be somewhere else in the caption bar.

Possibly something to do with the bounds or viewport of the window?

Regards,
Steve
gamedev101
 
Posts: 13
Joined: Thu Nov 28, 2019 7:43 pm


Return to Libgdx

Who is online

Users browsing this forum: MSN [Bot] and 1 guest