English subtitles

← Deep Dive Into Map Data - HTML5 Game Development

Get Embed Code
5 Languages

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

  1. >> Now let's take a little deeper look at what is contained inside of the data
  2. array. Now, if you recall, each layer is actually a large two-dimensional grid
  3. of tile data. It's listed here in the JSON file as a single integer array.
  4. Effectively, this is what we call raster scan order, where each row is listed in
  5. the file after the previous row, linearly. The value of each element in the data
  6. array actually has significance in itself. First off, if you see a zero value
  7. that effectively means that no tile has been placed in that x,y position inside
  8. of this layer. Any non-zero value represents a tile index for a given atlas.
  9. Now, this is where things start to get a little bit tricky. Now, if you recall,
  10. this little element here, first GID, that exists for each atlas that's listed in
  11. our tile sets array. Now, if a zero value in the data array for a layer, it
  12. means that there is no tile there. That means that the first element to
  13. represent that a tile does exist must start with one. Each atlas that exists
  14. inside of the tiled file will have an increasing first GID. Now, tiled has its
  15. own heuristics on what the first GID should be for each subsequent atlas that's
  16. loaded. We won't get into that other than to say that you need to know what this
  17. number is. So, what we see here is that if we have a value of 167 in this data
  18. array, and the first GID of the atlas starts with 1, this effectively means that
  19. 167 is the first atlas, tile number 166. Now, this makes a little bit more sense
  20. once you start getting 4 or 5 different atlas layers on there. Right now, it may
  21. seem a little bit [unknown]. The larger issue that you have to run into is what
  22. does 166 actually mean. Now, recall once again that the atlas that's being given
  23. to us is in raster scan order as well. So, the value of 166 is actually the
  24. raster index into the 2-dimensional array. With this set up, computing the
  25. coordinates for the atlas simply involves mapping the tile size to the right
  26. offset inside the atlas itself.