所以,我终于在libGDX中使用物理身体编辑器和Box2D制作了一个身体。现在我很想用libGDX创建一个优雅的触摸板。基本上,我是这样做的:
// Touchpad
private Touchpad touchpad;
private Touchpad.TouchpadStyle touchpadStyle;
private Skin touchpadSkin;
private Drawable touchBackground;
private Drawable touchKnob;
这就是我在create()
方法中写的:
// 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);
但是,当我测试它时,我发现没有渲染过触摸板。也许这都是关于相机的,所以有:
相机声明:
private OrthographicCamera camera;
相机视口声明:
private static final float VIEWPORT_WIDTH = 1920;
摄像头
create ()
方法:camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_WIDTH*h/w); camera.position.set(0, camera.viewportHeight/2, 0); camera.update();
我不知道,是不是回答我的问题需要的所有信息,所以为了清楚起见,整个班级都有