Search code examples
javaandroidcameralibgdxtouchpad

touchpad not showing and gives no errors


So, I've finally made a body using Physics Body Editor and Box2D in libGDX. Now I would love to create a classy touchpad using libGDX. Basically, I did it like the following:

// Touchpad
private Touchpad touchpad;
private Touchpad.TouchpadStyle touchpadStyle;
private Skin touchpadSkin;
private Drawable touchBackground;
private Drawable touchKnob;

and that is what i wrote in the create() method:

// Touchpad initialisation
    touchpadSkin = new Skin();
    touchpadSkin.add("touchBackground", new Texture("touchBackground.png"));
    touchpadSkin.add("touchKnob", new Texture("touchKnob.png"));

    touchpadStyle = new Touchpad.TouchpadStyle();

    touchBackground = touchpadSkin.getDrawable("touchBackground");
    touchKnob = touchpadSkin.getDrawable("touchKnob");

    touchpadStyle.background = touchBackground;
    touchpadStyle.knob = touchKnob;

    touchpad = new Touchpad(10, touchpadStyle);
    touchpad.setBounds(50, 50, 300, 300);

    stage = new Stage();
    stage.addActor(touchpad);
    Gdx.input.setInputProcessor(stage);

But, as I tested it, I discovered that no touchpad was ever rendered. Maybe that is all about the camera, so there:

  • camera declaration:

    private OrthographicCamera camera;

  • camera viewport declaration:

    private static final float VIEWPORT_WIDTH = 1920;

  • camera in create () method:

    camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_WIDTH*h/w); camera.position.set(0, camera.viewportHeight/2, 0); camera.update();

I do not know, is that all the information the one would need to answer my question, so just to be clear, there is the whole class


Solution

  • Actually, I've made a silly mistake - forgot to put the stage stuff in the render() method ))):

    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();