【问题标题】:Texture of ImageButton is not displayed on some devices when used TextureAtlas使用 TextureAtlas 时,某些设备上不显示 ImageButton 的纹理
【发布时间】:2014-07-13 20:27:37
【问题描述】:

我正在使用 libGDX 1.0,但不确定它是否是错误。

我的 ImageButton 使用 TextureAtlas 在 LG OPtimus 和 HTC Desire 上正确显示。但是,在 Galaxy Tab2 上,它会完全变回原样,但仍然可以点击。

如果我从 AssetsManger 加载它的纹理,一切都可以在任何设备上正常运行。

以下是代码的相关部分:

            stage = new Stage(new StretchViewport(fontCamera.viewportWidth,fontCamera.viewportHeight));

            ImageButtonStyle styleButtonPlay = new ImageButtonStyle();

            //this works
            //textureButtonPlay = new TextureRegion(game.manager.get("data/ui/play.png",Texture.class));
            //styleButtonPlay.imageUp =  new TextureRegionDrawable(textureButtonPlay);

            //this don't on Samsung Tab2
            atlas = new TextureAtlas("data/shot/atlas.pack");
            styleButtonPlay.imageUp =  new TextureRegionDrawable(atlas.findRegion("ui/play"));

            buttonPlay = new ImageButton(styleButtonPlay);
            buttonPlay.addListener(

                    new ClickListener() {
                        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
                        {
                            startGame();
                            return true;
                        }

                    });

            buttonPlay.setSize(80, 60);
            buttonPlay.setPosition(camera.viewportWidth/2 - buttonPlay.getWidth()/2,5);
            stage.addActor(buttonPlay);



我现在担心将我的所有精灵打包到单个图像上。

【问题讨论】:

    标签: libgdx


    【解决方案1】:

    问题已通过创建尺寸小于 4096x4096 的 texturepack.png 解决。 出于某种原因,它只在某些设备上是可以的,并且在桌面上没有发现类似的问题。

    希望这对某人有所帮助...

    【讨论】:

      【解决方案2】:

      在此处查看您的代码:

              atlas = new TextureAtlas("data/shot/atlas.pack");
              style.imageUp =  new TextureRegionDrawable(atlas.findRegion("ui/play"));
              ^^^^^
      
              buttonPlay = new ImageButton(styleButtonPlay);
                                           ^^^^^^^^^^^^^^^
      

      看起来您为 imageButton 分配了错误的样式,请尝试将可绘制对象放入正确的按钮样式(“styleButtonPlay”而不是“style”):

              styleButtonPlay.imageUp =  new TextureRegionDrawable(atlas.findRegion("ui/play"));
      

      【讨论】:

      • 谢谢@donfuxx。我忘记在我的问题中将“style”更改为“styleButtonPlay”。正如之前注释掉的那样,重构并没有改变变量的名称。此外,它确实解释了为什么它可以在 2 个真实设备上运行,而不是在 Galaxy Tab2 上运行。对不起,当我写这个问题时很愚蠢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-26
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      相关资源
      最近更新 更多