[Solved] Selecting objects problem (Again).

Alright, so I have this for loop that iterates constantly through all the ships and checks for stuff and what not. I want to be able to select a ship just by checking if it’s hovered. So far selecting works, but it also seems that as soon as I click the ship and set the currentShip to the clicked ship, the currentShip gets set back to null instantly. How do I keep currentShip from getting set back to null after I click the object?

if (ship.isHovered() && Gdx.input.isButtonPressed(Buttons.LEFT) && ship.getFaction() == 1) {
				currentShip = ship;
				updateFollowCamera(camera);
			}
			
			
		    if(Gdx.input.isButtonPressed(Buttons.LEFT) && ship.isHovered() == false && currentShip != null){
				currentShip = null;
			}

For your currentShip gets set back to null instantly, your isHovered() method must return false.

In your second IF, you are using ship.isHovered(), I think the correct is currentShip.isHovered(), because with only “ship” you are using the next and all the ships in every loop and not the “selected ship”.


          if(Gdx.input.isButtonPressed(Buttons.LEFT) && currentShip.isHovered() == false && currentShip != null){
            currentShip = null;
         }

If the first code is only to verify and select a currentShip, I think you can break the loop after you select a ship and use the second IF outside (based in other topics, your game has hundreds of ships right?).

Ah, couldn’t believe it was that simple. Thank you so much! ;D.