【问题标题】:android libgdx touchpad安卓 libgdx 触摸板
【发布时间】:2013-04-13 13:51:54
【问题描述】:

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

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  

}

【问题讨论】:

    标签: android libgdx touchpad


    【解决方案1】:

    我真的没有看到你犯的错误,但我正在努力提供帮助。 你的世界一定是一个舞台……当然。所以这就是我创建触摸板并将其添加到我的舞台的方法,它确实可以正常工作。您创建TouchpadStyle 时可能存在问题。
    Manager 是一个资产管理器,我在加载应用程序时加载了我的纹理。

    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);
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-24
      • 2018-07-13
      • 2014-07-08
      • 1970-01-01
      相关资源
      最近更新 更多