English subtitles

← Tile Packet - HTML5 Game Development

Get Embed Code
5 Languages

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

  1. Now that we have our tile sets parsed, we need a way to find the image and
  2. coordinate position of a specific tile in a tile set from our data array. Now to
  3. do this, we're going to have to create a new function called getTilePacket. That
  4. takes the index value we want from the data array of a layer, and determines an
  5. object like you see here. With the parameters of image set to the atlas image,
  6. and then px and py set to the x index and y index of the tile in the atlas. To
  7. grab the specific tile we want, we first need to lewd through all of the atlases
  8. in the tile sets array, checking the first GID of each one. If our first GID
  9. parameter is less than or equal to the tile index that we're given in this
  10. function, then we know that the tile we're looking for exists in that tile set.
  11. Once we have the correct tile set, we can grab the tile set image, and compute
  12. the necessary offset for the specific tile we want. Based on first GID, the
  13. number of tiles for across and down, and the size of the individual tile. This
  14. should be some easy math to determine the x and y value you need.