0

触摸板不可见,没有错误。他在“//创建触摸板皮肤”之间启动。我尝试了很多方法,但都错了。那里有什么问题?

public WorldRenderer(World world) {
    spriteBatch=new SpriteBatch();

    this.world = world;
    this.cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    SetCamera(CAMERA_WIDTH / 2f, CAMERA_HEIGHT / 2f);  

    loadTextures();


//Create a touchpad skin    

   Texture touchpadTexture = new Texture(Gdx.files.internal("data/touchpad.png"));
    touchpadTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);     
   TextureRegion background = new TextureRegion(touchpadTexture, 0, 0, 75, 75);
   TextureRegion knob = new TextureRegion(touchpadTexture, 80, 0, 120, 120);
   TextureRegionDrawable backgroundDrawable = new TextureRegionDrawable(background);
   TextureRegionDrawable knobDrawable = new TextureRegionDrawable(knob);
   Touchpad touchpad = new Touchpad(10, new Touchpad.TouchpadStyle(backgroundDrawable, knobDrawable));
   touchpad.setBounds(15, 15, 200, 200);
   world.addActor(touchpad);

    //Create a touchpad skin  

}
4

1 回答 1

4

I really do not see the misstake you made but i am trying to help. Your world must be a Stage.. for sure. So here is how i create my touchpad and add it to my stage and it does work without any problems. Maybe there is a problem with your creation of the TouchpadStyle.
The Manager is an assetmanager where i loaded my textures while loading the app.

private void initTouchpad() {
        skin = new Skin();
        skin.add("knob", this.game.manager.get("touchpad/touchKnob.png"));
        skin.add("background", this.game.manager.get("touchpad/test.png"));

        style = new TouchpadStyle();
        // skin.add
        style.knob = skin.getDrawable("knob");
        style.background = skin.getDrawable("background");

        pad = new Touchpad(10, style);
        pad.setBounds(0, Config.VIRTUAL_VIEW_HEIGHT - 150, 150, 150);
    }

//somewhere in my main
this.stage.addActor(pad);

Hope this may helps.

于 2013-04-14T21:07:04.763 回答