对于那些熟悉新LibGDX 0.98的人来说,这是一个问题.我不太确定,如何在Scene2d包中使用Drawable.我目前使用".png"作为各种类的背景的代码如下所示:
new TextureRegionDrawable(new TextureRegion(new Texture("data/splitpane.png")));
Run Code Online (Sandbox Code Playgroud)
有没有比这3个类更容易使用".png"作为Drawable的方法?
有没有办法将文本按钮中的文本对齐到左(或右)而不是中心?我找了它,但我似乎无法找到它.你可以使用.json皮肤文件做什么,如果是这样,怎么做?
谢谢,如果我不高兴请告诉我:)
这是一段代码片段.
itemList = new List(skin, "ariel.32.white");
String[] tmpInv = new String[b+1];
tmpInv[0] = "<Empty>";
a++;
for (Entry<String, String> entry : inventoryItems.entrySet()) {
tmpInv[a] = entry.getKey();
a++;
//String key = entry.getKey();
//Object value = entry.getValue();
// ...
}
Arrays.sort(tmpInv);
itemList.setItems(tmpInv);
inventoryPane = new ScrollPane(itemList, skin);
Run Code Online (Sandbox Code Playgroud)
这是我得到的,它工作正常.我想在每个项目前面添加描述性图标,但我似乎无法让它工作.我还需要一些方法来获取添加后所选内容的名称.目前我用
itemlist.getSelectedIndex();
Run Code Online (Sandbox Code Playgroud)

我想使用带有以下布局的scene2d包在LibGDX中创建一个游戏菜单屏幕
| label |
| btn btn btn |
| label |
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
Table table = getTable();
table.add(label1);
table.row();
table.add(button1);
table.add(button2);
table.add(button3);
table.row();
table.add(label2);
table.row();
Run Code Online (Sandbox Code Playgroud)
但不是我想要的,我得到这样的东西:
| label |
| btn btn btn |
| label |
Run Code Online (Sandbox Code Playgroud)
原因是因为每个table.add()方法调用都会创建一个新的单元格.但我想将所有3个按钮放在一个单元格内.我怎样才能达到预期的效果,可能在LibGDX中存在类似的东西LinearLayout或其他什么?
如何实现水平对齐按钮列表,其中一次只能检查一个按钮?我想为一个游戏实现这个目的,你必须从列表中选择工具并单击一个对象来执行一个动作.我想突出显示代表当前工具的按钮,以及当您选择另一个按钮以将前一个返回到非突出显示状态时以及已选择为突出显示状态的按钮时.因此,在任何给定时刻只能有一个工具处于活动状态,并且在您使用该工具并且未选择其他内容之后,应该没有突出显示的按钮.我过去两天尝试过自己实施,但我做不到.我想也许在libgdx scene2d中有这样的东西,但我没有找到任何东西.任何帮助或建议将不胜感激.
我正在尝试导入并运行此处列出的项目:
我首先下载zip文件,然后将其导入到eclipse中.从这里我得到以下三个错误(解决其他与错误的Android版本有关):
Description Resource Path Location Type
Unbound classpath variable: 'M2_REPO/junit/junit/4.5/junit-4.5.jar' in project 'game-test-desktop' game-test-desktop Build path Build Path Problem
Description Resource Path Location Type
Unbound classpath variable: 'M2_REPO/junit/junit/4.5/junit-4.5.jar' in project 'netthreads-libgdx' netthreads-libgdx Build path Build Path Problem
Description Resource Path Location Type
Unbound classpath variable: 'M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar' in project 'netthreads-libgdx' netthreads-libgdx Build path Build Path Problem
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?我注意到这个junit应该包含在Eclipse的JDT中,但是我已经安装了它而没有改变错误.谢谢.
我有以下SelectBox:
//Select Box Style
SelectBox.SelectBoxStyle boxStyle = new SelectBox.SelectBoxStyle();
boxStyle.fontColor = settingsFontColor;
boxStyle.background = new SpriteDrawable(rectangle);
boxStyle.font = skin.getFont("default");
boxStyle.scrollStyle = sps;
boxStyle.scrollStyle.background = new SpriteDrawable(rectangle);
boxStyle.listStyle = new List.ListStyle();
boxStyle.listStyle.font = skin.getFont("default");
boxStyle.listStyle.fontColorSelected = selectBoxSelectedColor;
boxStyle.listStyle.fontColorUnselected = selectBoxUnselectedColor;
boxStyle.listStyle.selection = new SpriteDrawable(selectBoxOption);
boxStyle.listStyle.background = new SpriteDrawable(selectBoxOption);
//SelectBox
String[] ballSpeeds = new String[]{"Slow", "Medium", "Fast", "Fastest"};
final SelectBox<String> ballspeedbox = new SelectBox<String>(boxStyle);
ballspeedbox.setItems(ballSpeeds);
Run Code Online (Sandbox Code Playgroud)
默认情况下,文本左对齐(慢,中,快,最快).如何将文本居中?
我不知道这是不是我,但是画画让我很困惑.他们是打算保持给定的尺寸,还是有办法在其中放大图像?我知道他们可以使用ninepatch通过拉伸图像来填充某些区域,但我想缩放它伸展的图像.我使用TextButton
作为我的菜单按钮,但它们太大了,我很想知道如何缩放它们.我正在从一张地图集中检索皮肤,其中有九个图像.这是设置屏幕:
以下是我正在使用的包中的图像:
这是TextureAtlas和Skin的初始化:
buttonAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
buttonSkin = new Skin(buttonAtlas);
Run Code Online (Sandbox Code Playgroud)
这是菜单按钮的初始化.
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);
}
});
Run Code Online (Sandbox Code Playgroud)
也许我可以改变我把它放在桌子上的方式,或者我如何把桌子放在舞台上?
table.add(buttonMenu).width(Gdx.graphics.getWidth()/4);
stage.addActor(table);
Run Code Online (Sandbox Code Playgroud)
作为最后的手段,我想我可以尝试创建自己的文本按钮演员,我可以缩放,谢谢你的时间.
我问过4天前的问题.得到了一些帮助,现在我的代码看起来像
ColorAction actionBtG = new ColorAction();
ColorAction actionGtB = new ColorAction();
SequenceAction sequenceAction;
RepeatAction repeatAction = new RepeatAction();
ShapeRenderer shapeRenderer;
Color blue = new Color(Color.BLUE);
@Override
public void create () {
shapeRenderer = new ShapeRenderer();
actionBtG.setColor(blue);
actionBtG.setEndColor(Color.GOLD);
actionBtG.setDuration(5);
actionGtB.setColor(blue);
actionGtB.setEndColor(Color.BLUE);
actionGtB.setDuration(5);
sequenceAction = new sequenceAction(actionBtG,actionGtB);
repeatAction = new RepeatAction():
repeatAction.setAction(sequenceAction);
repeatAction.setCount(RepeatAction.FOREVER);
}
@Override
public void render () {
repeatAction.act(Gdx.graphics.getDeltaTime());
Gdx.gl.glClearColor(1,1,1,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setColor(blue);
shapeRenderer.rect(100, 100, 40, 40);
shapeRenderer.end();
}
Run Code Online (Sandbox Code Playgroud)
但它仍然有效.它会动作一次并停止.当我需要循环时.从蓝色到金色,然后从金色到蓝色.我真的很感激任何帮助,因为我只是在学习libGDX.谢谢.
我已经阅读了所有答案并编辑了我的代码,但它仍然无效:
private Actor actionManager = new Actor();
ColorAction actionBtG = …Run Code Online (Sandbox Code Playgroud)