DIALOG problem

Anything libgdx related goes here!

DIALOG problem

Postby TruePlayer » Wed Aug 21, 2019 2:18 am

I created and added a dialogue as an actor on the stage, it appears for me only when the player collides with enemies. there are no problems.
Image

Code: Select all
dialog = new Dialog("GAME OVER", skin, "dialog") {
            public void result(Object obj) {
                if (obj.equals(true)){
                    isGame = false;
                    showDialog = false;
                    runReleased();
                    dialog.hide();
                    gsm.setState(1);
                }
                else if (obj.equals(false)){
                    isGame = false;
                    showDialog = false;
                    runReleased();
                    dialog.hide();
                    gsm.setState(0);
                }
            }
        };
        dialog.setScale(0.04f);
        dialog.text("PLAY AGAIN?");
        dialog.button("Yes", true); //sends "true" as the result
        dialog.button("No", false); //sends "false" as the result
        dialog.cancel();

        table.add(dialog).
                expandX().
                center().
                padTop(dialog.getHeight()/2).
                row();

        table.pack();

        stage.addActor(table);



I tried differently, this code is one of the last options.
I can not handle the click of a button. the button lights up red and nothing else happens.

the second problem is much more serious, I can’t establish a position.
why does the dialogue take place at 0,0 coordinates?
I declared a simple dialogue, I declared a dialogue as an actor and added to stage, I added dialogue to a centralized table and added a table to stage but this does not produce results, is it really impossible to change the position of the dialogue in the window? it's hard for me to believe.
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: DIALOG problem

Postby QuiIIraven » Wed Aug 21, 2019 4:06 am

Do you know how a debugger works?
If not try to learn it because it seems like you are spamming the forum for very basic things that you should be able to find out yourself.

E.g.
Is the result method called?
What are the values of obj?

Also, do not write "obj.equals(true)". Always write the non-null constant first like "true.equals(obj)". This way you avoid NullpointerExceptions in case obj is null.

And for sure you can center a dialog There are plenty of examples out there. Google it for more than 1 minute and I am sure you can find a solution.
QuiIIraven
 
Posts: 81
Joined: Sat Jun 02, 2018 4:59 pm

Re: DIALOG problem

Postby TruePlayer » Wed Aug 21, 2019 8:22 pm

All articles and videos say only one thing: that the dialogue is centralized independently. So it is, when I set the camera dimensions equal to the default resolution, my dialogue is really centered.
but I install the camera less than resolution!
my default resolution is 480 x 320, and the size of the camera is 10f x 7f (do not ask why I am doing this, just accept it).
I watched really many articles, tried to make the inner class, tried to make my own extens dialog, set the coordinates there, but the dialogue is still 0.0

I can use search, but my question is not covered anywhere

I tried to set the settings for the dialog location before the show method and after
Last edited by TruePlayer on Thu Aug 22, 2019 12:18 am, edited 1 time in total.
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: DIALOG problem

Postby TruePlayer » Thu Aug 22, 2019 12:17 am

Well, I had to change the conditional unit of my world, and now it is equal to one pixel of resolution
it saved me a few problems, including a sprite that wasn’t beautifully displayed (I won’t redraw them but just stretch them to pixels) and there are no more problems with the position of the dialog, I recommend it!

there is still a problem with the dialog buttons, they are pressed but nothing happens, someone can give advice where can I see?
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: DIALOG problem

Postby TruePlayer » Thu Aug 22, 2019 1:30 am

I accidentally solved my problem!)
for posterity, I say clearly: when added to InputMultiplexer, the order of addition plays a role! The code below is correct! Add stage first!

Code: Select all
InputMultiplexer im = new InputMultiplexer();
        GestureDetector gd = new GestureDetector(this);
        im.addProcessor(stage);
        im.addProcessor(gd);
        im.addProcessor(this);
        Gdx.input.setInputProcessor(im);
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: DIALOG problem

Postby aidenhart » Fri Aug 23, 2019 1:46 am

TruePlayer wrote:I accidentally solved my problem!)
for posterity, I say clearly: when added to InputMultiplexer, the order of addition plays a role! The code below is correct! Add stage first!

Code: Select all
InputMultiplexer im = new InputMultiplexer();
        GestureDetector gd = new GestureDetector(this);
        im.addProcessor(stage);
        im.addProcessor(gd);
        im.addProcessor(this);
        Gdx.input.setInputProcessor(im);

Thanks for sharing the code. It works!
aidenhart
 
Posts: 1
Joined: Fri Aug 23, 2019 1:43 am


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest