In my main game file, I do this in the render method of libgdx.
- Code: Select all
for (int x = 0; x < 30; x += 20) {
for (int y = 0; y < 30; y += 20) {
for (Image tile : map) {
float[] scale = getScale();
Image scaledTile = tile.getScaledInstance(
(int) (t.tilewidth * scale[0]),
(int) (t.tileheight * scale[1]), Image.SCALE_FAST);
g2d.drawImage(scaledTile, x, y, null);
}
}
}
The "map" variable is null. I initialize this thusly:
- Code: Select all
private ArrayList<Image> map;
then set it in the create method like this:
- Code: Select all
map = TMXLoader.drawMap();
Here is the drawMap method:
- Code: Select all
public static ArrayList<Image> drawMap() {
ArrayList<String> tileName = t.getTileSet();
ArrayList<Image> tiles = new ArrayList<Image>();
for (String name : tileName) {
tiles.add(Toolkit.getDefaultToolkit().getImage(name));
}
return tiles;
}
And here is getTileSet:
- Code: Select all
public ArrayList<String> getTileSet() {
ArrayList<String> tiles = new ArrayList<String>();
for (int i = 0; i < tilesets.size(); i++) {
tiles.add(tilesets.get(i).name);
}
return tiles;
}
I don't want to include all of the code on this forum, since that would make for quite a large post. So, I uploaded it below:
http://sdrv.ms/VTDtjP
I've spent quite awhile trying to figure out why it won't work, but I can't figure it out myself. I've never been good at thinking outside of the box, so someone else's viewpoint would be very helpful.
If someone can immediately spot something fishy, please tell me! If not, I'd really appreciate it if someone could take a look at my code, as I am completely stumped. Thank you very much for any help!
(I posted this in the Coderanch forum, since this forum isn't as active.)
