Libgdx : setting another screen, but still buttons from old screen active - java

In my libgdx game, I have 2 screens, menu and list.
When I click on a label in the menu screen, I do a setscreen(list).
The new screen shows up, and the menu screen alongwith its labels disappears.
But when I click on the same positions (from menu screen where the labels were, but of course those labels are not showing as I have changed screens) the click event responds. Why?
note:My list screen currently has not event handlers for any widget.
When switching screens do I need to do anything more than just setscreen(anotherscreen) to deactivate oldscreen?

I changed this :
I moved the input processor to the show() method of that screen using stage variable of that screen
public void show() {
...
Gdx.input.setInputProcessor(stage);
}
before I was setting this only in the constructor of the screen, so even If I was changing the screen, the input processor was still attached to the last created screen's stage

The answer above adiddnt work for me because I dont work with a InputProcessor in the 2nd screen.
My Solution was to set the Inputprocessor to null after setScreen.
Gdx.app.getApplicationListener().setScreen(new Screen());
Gdx.input.setInputProcessor(null);

Just broke my head over this. I changed screens in the show method but had Gdx.input.setInputProcessor(stage) called after that. The method still completed after the show method of the new screen ran and thus reverting back to the previous stage.
So make sure you call Gdx.input.setInputProcessor(stage) before you change screens or return after you change screens.

Related

Move a JDialog from outside the screen to a position in screen

I'm trying to create a notifications system.
I'm trying to make a JDialog thats moves from outside the screen to a specific position. I'm using timing framework and I can move the dialog from a position to another, but when I try to specify a position outside the screen the dialog does not do that.
This code:
dialog.setLocation(new Point(-dialog.getWidth(), 10));
Should put the dialog on the right side outside the screen but it does not.
I did try to use some notifications libraries as:
JCommunique
jtelegraph
twinkle
jcarrierpigeon
But any of those libraries work properly for my needs.

How do you make play again button in libgdx?

I have a button on my game where it set the screen on my game screen and it's located on my menu screen. So what happens is that when my character dies it just goes back to the menu screen, what I wan't to do is when I lose there will be just a button that will let you play again and a box that shows your score and the best score, I want to know what that box is called, is it just a texture that will show up when a condition is true? and also how do you make those effect where the button or text will go upwards and stop when they are the correct position (or other effects when they show up on the screen).
I find it unlikely that when your character dies the game automatically goes to the main menu screen again. It's more likely you are doing some tutorial or took some code that tells the program to go back to the main menu when the character dies.
Anyway, in my latest game I simply had a stack actor as the first actor on my stage. There I would just put in the interface and all like someone normally would. When I need a screen on top I would just add it to the base stack. This could be a pause display with a unpause, restart and exit button. Or this could be a game over screen where scores are calculated with exit and replay buttons.
Stage stage;
Stack stack; //scene2D.ui.Stack
Table mainTable;
Table overlayTable;
public GameScreen()
{
stage = new Stage();
stack = new Stack();
mainTable = new Table();
overlayTable = new overlayTable();
stage.addActor(stack);
stack.addActor(mainTable);
stack.addActor(overlayTable);
}
Now just setup the mainTable like you would normally layout your interface/game. The overlayTable is used to display stuff overlayed on your main table. I clear it when it's not needed anymore and build it up again when the player pauses or finishes the level. You can also use separate tables for this like pauzeTable, successTable, failedTable, etc. and hide or display these on demand.
For the effects you simply use Scene2D Actions, MoveToAction or MoveByAction specifically. You can set a action for each button/actor so you have more control over them individually or just a single MoveToAction for the whole table.
Table actionTable = new Table();
//position the table outside the screen
actionTable.setPosition(stage.getWidth(), 0); //Position on the right of the stage
MoveToAction moveAction = new MoveToAction();
moveAction.setPosition(0, 0); //Move from right side of stage inside the stage
moveAction.setDuration(.5f); //Duration of this action
moveAction.setInterpolation(Interpolation.fade); //Fade the movement in and out, many interpolations are supplied by the framework.
actionTable.addAction(moveAction); //Execute Action.

Codename One - autoscroll the screen

In a Codename One GUI builder app when I navigate back to my Main form, the screen is always shown at the top.
How can I get the screen to auto scroll down to the part I want and retain its previous scroll?
I'm assuming that this is a GUI builder app.
Normally this should be seamless as the UI will scroll to the last focused component but if you don't have focusable elements this might be harder. You can store the scroll Y value on the exitForm event and restore it the beforeShow event using something like:
f.addShowListener((e) -> f.scrollY(yValue));

Libgdx sidebar menu

I have red a lot of materials at this moment but I still can't find the answer. I'm trying to do this -
http://i.stack.imgur.com/K7CSr.png
I don't have reputation to post pictures so i will try to explain. A side menu which will open on click (over the game screen) that has a text or buttons on it. It is supposed to be transparent or if it is not achiavable just some color. It needs to interact with the GameScreen. I did a research but i can't find something similar, some kind of table or something. Any idea on that question ?
Since it looks like you haven't tried anything, I will only give you a rough logic of how its going to work.
You want to draw 'something' when the button is pressed. You can use a boolean to check if you want to show panel or not. In your render() method, you can put an if statement which would draw the menu in case showMenu == true. Menu is nothing more than a bunch of images that act as buttons when clicked on specified coordinates so it should be exactly same as drawing any other game element. In your InputProcessor, you can check if showMenu == true then check if the user clicked on any buttons on menu, otherwise if showMenu is not true, just skip the check for menu buttons. When the user presses the show/hide button again, change the showMenu boolean again from true to false or false to true.

Cant use capacitive buttons while touching the screen

I'm having issues while coding for my Evo. While touching the screen, the Evo interprets me touching the buttons as another press on the screen instead of a onKeyDown, onBackPressed, etc. (It actually sets the MotionEvent pointer count to 2, and I can get the co-ords that I'm touching that are off the main screen, for example, 830*190 when touching the back button.)
Short of coding in the locations of the buttons (which would be different for every phone with capacitive buttons, if they all have the same issue), is there any way to get around this? Does anyone else have this issue with a different capacitive buttoned device?
On the Evo, the area where the buttons are uses the same capacitive touch sensor as the screen. You can test this by loading up a webpage and scrolling until your finger is in the buttons region. Instead of pressing those buttons, you just continue to scroll around on the webpage, because as far as the phone is concerned you're still touching the "screen".

Categories