【发布时间】:2016-04-17 16:17:39
【问题描述】:
对于我的高级项目,我正在用 Java 编写游戏。它有一个正方形网格,您需要导航才能完成目标。我发现网格布局可以满足我的需要,只是我似乎无法让主角重叠(在上面)关卡上的空间。我基本上希望能够将“开始”图标与“空”等任何其他图标重叠。我还没有找到这样做的好方法(当然我是新手)。我想知道如何做到这一点,或者即使我不能。如果我做不到,请留下一个链接,以展示我可以实现目标的方法。
以下是与设置关卡相关的代码片段。当我尝试将主角添加到网格上的指定区域时,它只会将所有内容推高 1。
public loadWindow() throws IOException {
try{
level = new FileReader("levels/debug1.txt");
while ((type = level.read()) != -1){
if (type == 'a'){
icon = start;}
if (type == 'b'){
icon = empty;}
//Includes the rest of the if statemets
if (type == 'x'){
test = false;}
if (test == true){
JLabel spot = new JLabel(new ImageIcon(icon));
add(spot);}
}
} finally {
if (level != null){
level.close();
}
}
}
【问题讨论】:
-
威廉,你说的重叠是什么意思?
标签: java components jlabel grid-layout