Libgdx and Box2D with android studio: Why isn’t the ball responding to touch inputs?

public void create () { 

. . . . . Gdx.input.setInputProcessor(new PlayerControl(camera, BallBody));


        public boolean isPointOnPlayer(float x, float y){             for(Fixture fixture : BallBody.getFixtureList())                 if(fixture.testPoint(x, y)) return true;             return false;         }      public class PlayerControl extends InputAdapter {                  private Vector3 _touchPosition;          public PlayerControl(Camera camera, Body ballBody) {             _touchPosition = new Vector3();         }          @Override         public boolean touchDown(int screenX, int screenY, int pointer, int button) {             // don't forget to unproject screen coordinates to game world               camera.unproject(_touchPosition.set(screenX, screenY, 0F));             if (isPointOnPlayer(_touchPosition.x, _touchPosition.y)) {                 // touch on the player body. Do some stuff like player jumping                 BallBody.applyForce(new Vector2(0, 100f),new Vector2(0, 10f),true);                   return true;              } else                 return super.touchDown(screenX, screenY, pointer, button);         }       } 

How to integrate Firebase to Libgdx?

I have an android game built with libgdx and what I’d like to do is to add some kind of authentication so I can connect the game with user data to firebase database.

I have some experience with firebase using it in native android apps, but I have no idea on how to connect "native code" with libgdx.

Researching I found these third party libs and

But as it does not provide any example it didn’t help me much.

So what’s the best way to "mix" native android code and libgdx? I want to be able to achieve things like storing data on db, implementing in-app-purchases, authenticating users. If I’m looking the wrong way please let me know too.

LibGDX How to adjust mouse aim angle calculation when screen is resized

I’m starting with a screen resolution of 1280 x 960 and that is the default resolution where mouse aiming is calculated thus:

angleRad = (float) (Math.atan2(screenX - (screenWidth / 2), screenY - (screenHeight / 2))); angle = (float) Math.toDegrees(angleRad - Math.PI / 2); angle = Math.round(angle) <= 0 ? angle += 360 : angle; if (Math.round(angle) == 360)     angle = 0; 

Which all works fine. But when the game is resized to some resolution with a vastly different ratio to the default, like for example 2560 x 1440 at full screen in my case, the aiming is off. The resize method is like this:

@Override public void resize(int width, int height) {     game.getViewport().update(width, height);     control.screenWidth = width;     control.screenHeight = height; } 

Where control.screenWidth and control.screenHeight are used in the above angle calculation and as the set resolution in other areas. The angle calculation when resized is roughly correct but tends to get further and further off course the further the aim is away from the player.

If the player aims straight up, down, left or right (N, S, W or E basically) then the aim is dead on, but veers off as aiming goes away from the player towards a screen edge – no doubt due to the resolution ratio difference.

We have these ratio differences which no doubt affect the angle calculation:

1280x960 1.33 ratio 2560x1440 1.77 ratio 

But I’m not sure how to take into account these ratios to adjust the angle calculation accordingly in my code?

Libgdx – TextButtons added to Table – clicklistener not working [closed]

I am having issues trying to implement a menu in a previously created game. I am pretty new to Libgdx and not sure how everything works just yet. I am adding a menu to an already created game scene using a table and text buttons.

My goal:

  1. Click button which shows table full of buttons
  2. Click specific table button and do something with them
  3. Click away from the table area then table/buttons will disappear

I’ve got it all working except connecting the buttons to clicklisteners. I can only think of the buttons not actually being on the top surface where you can click them.

Section of code: Shortened for brevity; class implements InputProcessor

    protected MenuComponent(GameContext context, SeaBattleScene owner) {         super(context, owner);         this.context = context;     }      @Override     public void create() {         batch = new SpriteBatch();         this.stage = new Stage();         Gdx.input.setInputProcessor(stage);         menuUp = new Texture("assets/ui/disengage.png");         menuDown = new Texture("assets/ui/disengagePressed.png");         menuWindow = createMenuWindow();         menuWindow.setVisible(false);         stage.addActor(menuWindow);         stage.getRoot().setPosition(65,150);     }      @Override     public void update() {     }      @Override     public void render() {         batch.begin();         batch.draw((menuButtonIsDown)?menuDown:menuUp, MENU_buttonX, MENU_buttonY);         batch.end();         stage.act();         stage.draw();     }     private Table createMenuWindow() {         //Table View         Table table = new Table();         table.setPosition(675,160);         //Button View         SpriteDrawable upFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         SpriteDrawable downFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         SpriteDrawable checkedFormat=new SpriteDrawable(new Sprite(createRoundPixMap(Color.BLACK,100, 30,10)));         TextButtonStyle buttonStyle=new TextButtonStyle(upFormat, downFormat, checkedFormat, new BitmapFont());         //Individual Buttons         TextButton lobbyButton = new TextButton("Back to Lobby",buttonStyle);         lobbyButton.addListener( new ClickListener() {                           public void clicked(InputEvent event, float x, float y) {                 System.out.println("Clicked");             };         });         TextButton mapButton = new TextButton("Show Maps",buttonStyle);         table.add(lobbyButton).pad(3,0,3,0).row();         table.add(mapButton).pad(3,0,3,0).row();         return table;     }           public static Texture createRoundPixMap(Color color, int width,             int height, int cornerRadius) {         Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.Alpha);         pixmap.setBlending(Pixmap.Blending.None);         pixmap.setColor(color.r,color.g,color.b,0.4f);         pixmap.fillCircle(cornerRadius, cornerRadius, cornerRadius);         pixmap.fillCircle(width - cornerRadius, cornerRadius, cornerRadius);         pixmap.fillCircle(width - cornerRadius, height - cornerRadius, cornerRadius);         pixmap.fillCircle(cornerRadius, height - cornerRadius, cornerRadius);         pixmap.fillRectangle(0, cornerRadius, width, height - (cornerRadius * 2));         pixmap.fillRectangle(cornerRadius, 0, width - (cornerRadius * 2), height);         Texture texture = new Texture(pixmap);         pixmap.dispose();         return texture;     } 

Can someone expain or show me what I am doing wrong, so I can fix it to where I can use the buttons?

This is basically what it looks like: Menu

Best way to make a Side Panel UI with Libgdx? (Java)

Take this image for example, the game is called Realm of the mad god, and it has this side panel filling the whole screen height with the player info.

To reproduce it, Is there any way to make the game "view" smaller so I can fit the side panel to its right without literally overlaying the game, PROBABLY like this game did, or is the only way out to overlay the game?

(Tibia might also be an example of a game smaller then its UI)

Side Panel example

Libgdx Recoil Effect

I set -velocityX to my sprite gun.

float velocityX = -20 * dt; if(trigger) {    gun.setX(gun.getX() + velocityX); } 

I basically set a velocity of -20m/s to my gun vertex X. The problem is when I rotate the gun in a vertical position or example: 30degree angle.

enter image description here

How can I add recoil effect even if the sprite is not in a horizontal position, or should I just add it in the animation?

Create Scoreboard using LibGDX table layout

I am trying to create a card game, which will contain following features.

  • It will be a 6 player game.
  • Each player contain set of cards, where each card contain some specific value
  • After every round a “Scoreboard” will be shown, that contains score of each round and total score.

I want to create a Scoreboard like below image.

enter image description here

I am trying to create it using LibGDX table layout, but the Table Wiki doesn’t help at all for this kind of layout and I can’t find any tutorials or examples on the web that would help.

Following are my code to create scoreboard, currently i am able to reach this far only.

Score Board Class

public class ScoreBoard { private Stage stage; private Assests assests; Skin skin; Container<Table> tableContainer; private AbstractGameController gameController; private ArrayList<Player> players = null;  public ScoreBoard(Stage stage, Assests assests, AbstractGameController gameController) {     this.stage = stage;     this.assests = assests;     skin = assests.manager.get(Assests.glassySkin);     tableContainer = new Container<Table>();     this.gameController = gameController; }   float sw =; float sh =;  float cw = sw * 0.7f; float ch = sh * 0.5f;  public void displayScoreCard() {     if (players == null)         players = gameController.getPlayers();     tableContainer.setSize(cw, ch);     tableContainer.setPosition((sw - cw) / 2.0f, (float) sh - ch);     tableContainer.fillX();      Table table = new Table(skin);     table.setDebug(true);     Label topLabel = new Label("Score Board", skin);     topLabel.setAlignment(;     table.row().colspan(players.size()).expandX().fillX();     table.add(topLabel).fillX();     table.row();     for (int i = 0; i < players.size(); i++) {         table.add(new Label(players.get(i).getName(), skin)).uniform();     }     table.row();     for (int i = 0; i < 6; i++) {         for (int j = 0; j < players.size(); j++) {             if(players.get(j).getPreviousRoundScoreByIndex(i)>=0)             table.add(new Label(players.get(j).getPreviousRoundScores().get(i).toString(), skin));         }         table.row();     }        tableContainer.setActor(table);     stage.addActor(tableContainer); } } 

Game Play Screen

 public GamePlayScreen(Assests assests) {     this.assests = assests;     camera = new OrthographicCamera();     width =;     height =;     camera.setToOrtho(false, width, height);     camera.update();     batch = new SpriteBatch();     FillViewport viewport = new FillViewport(width, height, camera);     viewport.update(width, height, true);     Gdx.input.setCatchKey(Input.Keys.BACK, true);     stage = new Stage(viewport);     stage2 = new Stage(viewport);     stage3 = new Stage(viewport);     gameDrawer = new GameDrawer(batch, assests);     gameController = new GameController(camera, assests);     scoreBoard = new ScoreBoard(stage3, this.assests, gameController);     gameController.setScoreBoard(scoreBoard);   }  public void show() {     //, "Enters show method");     Image backgroundImage = new Image(assests.manager.get(Assests.backgroundImageTexture));     backgroundImage.setSize(width, height);     stage.addActor(backgroundImage);     InputMultiplexer multiplexer = new InputMultiplexer();     multiplexer.addProcessor(stage);     multiplexer.addProcessor(stage2);     multiplexer.addProcessor(stage3);     multiplexer.addProcessor(new GestureDetector(new TouchController(gameController)));     Gdx.input.setInputProcessor(multiplexer);     batch.setProjectionMatrix(camera.combined);       //, "Executed show method succussfully"); }  public void render(float delta) {     //, "Enters render method");, 0.246f, 0.621f, 1.0f);;     if (Gdx.input.isKeyPressed(Input.Keys.BACK))         onBackPressed();     stage.act();     stage.draw();      batch.begin();     gameController.processGameRender();      gameDrawer.drawDealtDeck(gameController.getDealtDeck());     gameDrawer.drawDiscardedDeck(gameController.getDiscardedDeck());      gameDrawer.drawPlayerDeck(gameController);     scoreBoard.displayScoreCard();      batch.end();     stage2.act();     stage2.draw();     stage3.act();     stage3.draw();      //, "render metod executed succussfully"); } 

ImageButton en libGDX

Buen dia, Estoy inentando crear un boton en LibGDX soy nuevo en esto de la creacion de videojuegos y he visto varas formas de implementarlo, el problema es ese mismo IMPLEMENTARLO en mi codigo, nose como hacerlo? este metodo es el que utilizo para navegar entre pantallas pero dando click a la pantalla NO al boton, si alguien me podria ayudar le agradeceria mucho con esto aqui les dejo el codigo de mi clase.

┬┤public class MenuState extends State {

//Dimensiones a utilizar para las imagenes de inicio private static final int WIDTHPLAY = 275; private static final int HEIGTHPLAY = 200; private static final int WIDTHPAJARO = 150; private static final int HEIGTHPAJARO = 150; private static final int WIDTHPLETRAS = 425; private static final int HEIGTHLETRAS = 100;  private Stage stage; private TextButton button; private TextButton.TextButtonStyle textButtonStyle; private BitmapFont font; private Skin skin; private TextureAtlas buttonAtlas;  //Declaracion de los assets a utilizar en la pantalla principal //La palabra Texture es una libreria para agregar texturas en libGDX private Texture background; private Texture btninicial; private Texture imagenPajaro; private Texture imagenLetras;    public MenuState(GameStateManager gameStateManager) {     super(gameStateManager);      //Inicializar las variables de los assets y agregar las imagenes     background = new Texture("bgprincipal.jpg");     btninicial = new Texture("play.png");     imagenPajaro = new Texture("pajaro.png");     imagenLetras = new Texture("iniciotexto.png");      }     /*  * HandleInput evalua todas las entrasa que  * tendremos es decir cuando estamos interactuando  * con el  */   @Override public void HandleInput() {     /*      * Metodo para definir cuando se      * este tocando la pantalla pantalla      * principal navege hacia la segunda      */       if (Gdx.input.justTouched()) {         gsm.set(new PlayState(gsm));         dispose();    }  }    /*  * update ejecuta los metodos que realizamos  * al interactuar con la pantalla  */ @Override public void update(float dt) {  HandleInput(); //Mandamos a llamar este metodo }