I am quite new to LibGDX. I am trying to make a game, where the character is an Actor, and it’s controlled by a Touchpad(included in the main Stage as an Actor too). My problem is that I am trying to put the stage’s camera to be always centered in the character, but I have no idea of how to solve this, I’ve been searching and it seems I have to use 2 cameras, 1 to show the controllers(the touchpad), and another to show the actors and that stuff, so while the actors are moving, the touchpad will keep on the screen, but I do not really know how should I do this, my code is this:
public class GameScreen extends BaseScreen {
Stage stage;
Character character;//it extends from actor
Touchpad joystick;
int screenWidht, screenHeight;
Skin joystickSkin;
public GameScreen(AwesomeTanks game) {
super(game);
screenWidht = Gdx.graphics.getWidth();
screenHeight = Gdx.graphics.getHeight();
joystick = new Touchpad(0,getTouchPadStyle());
joystick.setColor(joystick.getColor().r, joystick.getColor().g, joystick.getColor().b, 0.5f);
joystick.setBounds(10, 10, screenHeight / 2.5f, screenHeight / 2.5f);
character = new Character();
stage = new Stage();
stage.addActor(character);
stage.addActor(joystick);
Gdx.input.setInputProcessor(stage);
}
@Override
public void hide() {
stage.dispose();
joystickSkin.dispose();
character.detach();
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
character.moveBy(joystick.getKnobPercentX() * character.velocity * delta, joystick.getKnobPercentY() * character.velocity * delta);
if(joystick.isTouched())
character.setRotation((float) ((180/Math.PI)*Math.atan2(joystick.getKnobPercentY(),joystick.getKnobPercentX())));
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
}
Sorry for my English.