Libgdx 使用TextureAtlas时,某些设备上不显示ImageButton的纹理
我正在使用libgdx1.0,不确定它是否是一个bug 我的ImageButton使用TextureAtlas在LG OPtimus和HTC Desire上正确显示。然而,在Galaxy Tab2上,它会完全返回,但仍然可以单击 如果我从AssetManager加载它的纹理,任何设备上的一切都可以正常工作 以下是守则的相关部分:Libgdx 使用TextureAtlas时,某些设备上不显示ImageButton的纹理,libgdx,Libgdx,我正在使用libgdx1.0,不确定它是否是一个bug 我的ImageButton使用TextureAtlas在LG OPtimus和HTC Desire上正确显示。然而,在Galaxy Tab2上,它会完全返回,但仍然可以单击 如果我从AssetManager加载它的纹理,任何设备上的一切都可以正常工作 以下是守则的相关部分: stage = new Stage(new StretchViewport(fontCamera.viewportWidth,fontCamer
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);
我现在关心的是如何将我的所有精灵打包到一张图像上。请参见此处的代码:
atlas = new TextureAtlas("data/shot/atlas.pack");
style.imageUp = new TextureRegionDrawable(atlas.findRegion("ui/play"));
^^^^^
buttonPlay = new ImageButton(styleButtonPlay);
^^^^^^^^^^^^^^^
看起来您为imageButton指定了错误的样式,请尝试将drawable设置为正确的按钮样式(“styleButtonPlay”而不是“样式”):
通过创建一个小于4096x4096的texturepack.png,该问题已得到解决。 出于某种原因,它只在某些设备上正常,在桌面上没有发现类似的问题
希望这能帮助某人…谢谢@donfuxx。我忘了在我的问题中将“style”改为“styleButtonPlay”。正如之前被注释掉的那样,re因子没有改变变量的名称。此外,它也解释了为什么它可以在2台真实设备上工作,而不能在Galaxy Tab2上工作。对不起,我写这个问题的时候太傻了。
styleButtonPlay.imageUp = new TextureRegionDrawable(atlas.findRegion("ui/play"));