English subtitles

← ViewRect - HTML5 Game Development

Get Embed Code
3 Languages

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

  1. The first thing we have to do is actually test whether or not the boundaries of
  2. this style intersect with the boundaries of the view rectangle. Now if you look
  3. online you can actually find some really nice blocks of code that are 2D
  4. rectangle to 2D rectangle testing. Effectively we're playing the same principle
  5. here. We compute the boundaries of the x and y of the actual tile and world
  6. space. And test this against our view rectangle boundaries as well. If the tile
  7. lands outside of the viewRect, or it's not intersecting with the viewRect, then
  8. it's not visible and we can move on. For those tiles that past this test, we
  9. actually modify the worldX, and worldY translating it by the inverse of the
  10. viewRect off set. What this is going to do is it's going to take our viewRect
  11. and actually recenter it on the canvas itself, so that the worldX and worldY
  12. coordinates are actually canvas oriented rather than world oriented. These
  13. values are then passed down to canvas.drawimage directly and the image will
  14. magically appear on the screen.