- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最近我一直在尝试制作一个小游戏来达到我的学习目的,但我陷入了困境。我能够从 .txt 文件生成 map ,但它似乎将其绘制为侧面?
这是我加载的 map ,它从文本文件中读取并将它们添加到 ArrayList 中。宽度为 20,高度为 10。同样的情况也适用于我的 map ,20 行宽,10 下。
public void loadMap(String name) {
try {
this.name = name;
FileInputStream file_stream = new FileInputStream(name);
DataInputStream in = new DataInputStream(file_stream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
map = new Tile[WIDTH][HEIGHT];
String line;
int y = 0;
while ((line = br.readLine()) != null) {
String[] tokens = line.split(" ");
for (int x = 0; x < WIDTH; x++) {
boolean f = false;
if (Integer.parseInt(tokens[x]) == 1)
f = true;
Tile tile = new Tile(y, x, f, Integer.parseInt(tokens[x]));
tiles.add(tile);
map[x][y] = tile;
System.out.println("adding tile (x: " + x + " y: " + y + ") " + f + " " + Integer.parseInt(tokens[x]));
}
y++;
}
in.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "The map: " + name + " was not found.");
e.printStackTrace();
}
}
这是 map 的绘制方法
public void paint(Graphics2D g) {
for (Tile t : getTiles()) {
t.draw(g);
//g.draw(t.getBounds());
}
}
这是一个示例 map
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
它绘制 map 的方式基本上是垂直版本,而不是像上面那样的正确方式。我尝试弄乱 mapLoaded 中的数字(宽度、高度)并切换 x 和 y,但似乎没有任何效果。请帮忙
最佳答案
您只需更改 Tile tile = new Tile(y, x, f, Integer.parseInt(tokens[x]));
到 Tile tile = new Tile(x, y, f, Integer.parseInt(tokens[x]));
.
每次你制作一个新的图 block 时,你都会切换 x 和 y,这会导致你的问题。
关于Java Tiled map 正在横向绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21359774/
这是引用 Google Tile Map 或 Bing Maps。是否可以在不使用任何类型的内部计算指定缩放级别(或 LevelOfDetails)的情况下获得 Tile Count、Tile X、T
我有一个 Tiles 模板,其中每个页面都提供一个标题,一些要添加到 中的内容,要放入一些混凝土的东西 ,以及附加到 的内容在一切之后。 大部分内容都非常小,因为页面是用 JS 呈现的。 我怎样才
我正在使用 Apache Tiles 2.1 开展一个项目。 我遇到了一个问题,即使用列表属性扩展模板会创建这些列表项的重复项...每个继承级别都有一组重复项。 作为示例,以下是基本定义及其将生成的页
我在 HTML 的背景层中有一个重复的水平图案。我可以使用 1 像素宽的图像或它的倍数(10、20、50...)来实现。 问题是: 哪个更好? 使用薄(小文件大小)图像并使其重复很多 使用更大的图片,
我们正在使用 Apache Tiles 3.0。 在我们的 Apache Tiles-Def 文件中,我们偶尔会遇到此 DTD 引用的问题,这可能是因为该站点不可靠。偶尔会出现“Reading Def
我在我的网络应用程序中使用 Tiles。我在瓷砖中使用了标准布局 (standard.jsp)。在 standard.jsp 之上有很多包含,涉及标签库等。 让我们做一个简化的例子。 标准.jsp:
我正在制作一个基于 2d tile 的游戏,我试图通过对 tile 结构中的值使用位字段和字节来保持我的 tile 结构小: struct Tile { // 3 bytes (24 bits
我已经在 Tiled 中制作了一张 map ,并且已经生成了一个 JSON。每当我尝试在 Chrome 中加载 map 时,它根本无法加载。当我去检查网站时,有类似警告: 在来自 Tiled 的 Js
我使用 struts 2.3.16 和 tiles 2.0.6。 具有空属性(以及其他属性)的图 block 定义: 一些其他定义扩展了它,他们可以选择填入值: 或者也留空。 我试图通过使用 st
我想在Struts2框架中使用tile。作为用于显示图 block 内容的标签,tiles:insert 和tiles:get 之间的基本区别是什么? 最佳答案 is equivalent to
我正在从 Strut1 + Tiles 项目迁移到 SpringMVC 和 Apache Tiles 3。我对Struts1+Tiles只了解一点点,它太旧了,我陷入了Struts-tiles中的Co
我正在使用Tiles,Spring和Hibernate创建一个应用程序。 在运行时,它显示以下错误: Can not find the tag library descriptor for "http
目前我在计划任务的帮助下实现了我的翻转图块,因此类似方法的一个问题是翻转图块将在时间间隔内翻转相同的图像。所以我想要实现的是我需要像循环瓷砖一样翻转我的图像。即一个接一个的方式。这里要注意的一件事是我
我正在使用 v0.6.2 和 Cocos2D v0.99.5,现在我真的非常需要为我的一些图 block 制作动画。我读了part of a wiki关于如何为图 block 制作动画,但它似乎与 M
我有一个图 block ,其中列出了提供给它的对象中的文章。此图 block 是大多数页面的一部分,但不是全部页面。有没有什么方法可以自动仅向需要它的页面提供对象(包含特定图 block )?现在我只
我正在寻找一种解决方案,以根据游戏 block 的类型对我的游戏 block 进行分组。瓷砖存储在二维数组中,类型为空和水,分组的瓷砖将存储在组类中。 所以如果我有二维数组: 0, 0, 0, 0,
我在今天的 maven 构建过程中遇到以下错误。 Unable to resolve artifact: Unable to get dependency information: Unable to
我正在尝试让 Apache Tiles' put-list-attribute 与 Thymeleaf 一起工作。 这是我尝试过的: 来自 Tiles 配置: 来自 thymlea
我在 UI 的 mat-grid-list 中动态显示 mat-grid-tile,其数量和数据随着后端值的变化而变化。它们是动态生成的。单击任何 mat-grid-tile 都会调用一个函数并将数据
我制作了一个 Tiled 游戏。现在,我正在通过增加场景中的节点数量来对手机的功能进行压力测试。有基于物理的东西,AI 运动,日夜系统,粒子在这里和那里突然出现以及我的场景的引擎盖下发生的许多其他事情
我是一名优秀的程序员,十分优秀!