English subtitles

← Loading Tileset Data - HTML5 Game Development

Get Embed Code
5 Languages

Showing Revision 6 created 05/25/2016 by Udacity Robot.

  1. >> Fantastic. The solution for this is pretty straight forward, based upon what
  2. we've already seen. Firstly, we walk through all the tile set's inside of the
  3. map object that we've created. For each one of them, we've created a new image,
  4. set it's on load function, and then set it's source name. Once we are loaded,
  5. effectively we increment the imgLoadCount variable, and then we test if the
  6. imgLoadCount variable is equal to the number of tile sets that could potentially
  7. occur. So effectively, we are saying that our number of images loaded equal to
  8. number of images that exist. If so, we can set fully loaded to true. Now, you'll
  9. notice one annoying little variants of the JSON format for tiled, is that the
  10. image path is actually an absolute path to the file from where the editor and
  11. base file were formed. So effectively, what this is saying is that, given the
  12. path to tiled, there's some really crazy file path to actually get to the grid's
  13. master PNG from the source file we're using. So, to properly load that, what
  14. we'd like to do is strip out all of the other data that's not just the file
  15. name. And then, append the file name to our data directory. Now, this is because
  16. our editing environment may be in a different directory structure than our
  17. production environment that users are actually playing. For grids, we use this
  18. nifty little regular expression here that allowed us to replace all of the data
  19. before the final slash with blank characters, giving us the file name for this
  20. image. We appended that filename to the ../data directory, giving us the source.