Can't figure out why my TMX loader won't work

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Can't figure out why my TMX loader won't work

Postby lowena » Thu Jan 10, 2013 12:12 am

Hey guys. I'm having trouble with a part of my project, specifically the TMX loader. More specifically, it appears that information is not being stored in variables correctly, or maybe I'm accessing them at the wrong time, I'm not sure which. I'll go through what's not working.

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.)
lowena
 
Posts: 10
Joined: Mon Jan 07, 2013 1:03 am

Re: Can't figure out why my TMX loader won't work

Postby Pinkie Swirl » Sun Jan 13, 2013 1:13 am

Any reason you don't use the tile map loader from libgdx for tmx files?

Otherwise you do not provide your tmxloader classes, so i can't test it.

And why are all your assets duplicated and why are you using Graphics2d? That looks like a mix between all different kind of things, i would not be surprised if "nothing" works xD
Pinkie Swirl
 
Posts: 717
Joined: Thu Sep 20, 2012 8:55 pm


Return to General Development

Who is online

Users browsing this forum: Google [Bot] and 2 guests