我不知道是不是只有我,但是drawables把我搞糊涂了。它们是打算保持给定的大小,还是有一种方法来缩放其中的图像?我知道他们可以使用ninepatch通过拉伸图像来填充某些区域,但我想缩放它拉伸的图像。我的菜单按钮使用的是TextButton,但它们太大了,我想知道如何缩放它们。我正在从一本地图集中检索皮肤,里面有九张图片。以下是设置屏幕:

以下是我正在使用的包中的图像:

下面是TextureAtlas和皮肤的初始化:
buttonAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
buttonSkin = new Skin(buttonAtlas); 下面是菜单按钮的初始化。
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = Assets.buttonSkin.getDrawable("bluebutton");
textButtonStyle.down = Assets.buttonSkin.getDrawable("redbutton");
textButtonStyle.font = font;
buttonMenu = new TextButton("Menu", textButtonStyle);
buttonMenu.pad(20.0f);
buttonMenu.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.fade.startFadeOut();
super.clicked(event, x, y);
}
});也许我可以改变我把它放在桌子上的方式,或者我把桌子放在舞台上的方式?
table.add(buttonMenu).width(Gdx.graphics.getWidth()/4);
stage.addActor(table);作为最后的手段,我想我可以尝试创建我自己的文本按钮演员,我可以扩展,感谢您的时间。
发布于 2014-06-18 02:21:10
首先,如果您知道您的图像太大:最好的方法是将图像本身缩放到较小的大小,然后使用TexturePacker生成包含较小图像的新TextureAtlas。
无论如何,如果您确实想要,可以使用TableLayout缩放图像按钮,请参见示例:
table.add(buttonMenu).width(100).height(100);发布于 2014-09-01 14:00:30
上面的答案对我不起作用,但我有一个解决方案。
您可以制作辅助摄影机并将其附加到舞台上。要缩放表,只需缩放次相机的视口大小
下面是一个例子:
//Heres where you set the scale of your buttons and your table
Camera secondaryCamera = new Camera(Gdx.graphics.getWidth() * scale,
Gdx.graphics.getHeight() * scale);
Stage stage = new Stage();
Table table = new Table();
ImageButton button = new ImageButton(drawableUp, drawableDown, drawableChecked);
table.setFillParent(true);
stage.getViewport().setCamera(secondaryCamera);
table.add(ImageButton);
stage.addActor(table);当你使用它来进行触摸控制时,这是非常有效的。您可以为整个UI使用一个表格,并根据您的喜好进行缩放,独立于您的其他游戏项目;
发布于 2016-03-20 15:00:55
table.add(buttonMenu).width(100).height(100);应该可以工作,您只需要根据自己的喜好调整width和height参数,也可以使用setBounds方法。下面是一个示例:
TextButton myButton = new TextButton("Press Me", style);
myButton.setBounds(xCoordinate, yCoordinate, width, height);https://stackoverflow.com/questions/23594611
复制相似问题