Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Fiona Heiss
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



The "map" variable is null. I initialize this thusly:



then set it in the create method like this:



Here is the drawMap method:



And here is getTileSet:



In addition, the line "g2d.drawImage(scaledTile, x, y, null);" is never called, which makes me think "map" is null, but I can't figure out why...

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 on the libgdx forum, but it's not very active, so I thought I might get more help here, if that's fine)
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fiona Heiss wrote:More specifically, it appears that information is not being stored in variables correctly

This sort of thing should not really cross your mind. Variables work in Java. Always look in your own code (until you get confirmation from outside).

or maybe I'm accessing them at the wrong time

That's what you should be looking for, it is the most likely scenario.

The "map" variable is null. I initialize this thusly:

How do you know it is null? Do you get a NullPointerException?

In addition, the line "g2d.drawImage(scaledTile, x, y, null);" is never called, which makes me think "map" is null, but I can't figure out why...

How do you know that method is never called? Have you tried println statements or running through a debugger? That method wouldn't get called if map was not null, but was empty as well. Have you checked the values in the Lists as you enter and access them to make sure they exist, are what you think they are, and produce the results that you expect?
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fiona Heiss wrote:(I posted this on the libgdx forum, but it's not very active, so I thought I might get more help here, if that's fine)


That is okay, but could you post a link to the topic in the other forum here, and post a link in the other forum back to this thread so we all know who's working on it and what answers you receive?

Thanks,
 
Fiona Heiss
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will do!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic