Return to Video

Implementing Z-Ordering - HTML5 Game Development

  • 0:00 - 0:04
    You'll soon notice an issue with our setup. If we walk through our entities and
  • 0:04 - 0:07
    render them in the list as they've been allocated, then we get into situations
  • 0:07 - 0:11
    that some objects will render above or below other objects, which may cause
  • 0:11 - 0:17
    visual issues. For instance, explosions should draw above everything else. But
  • 0:17 - 0:20
    with our current setup, this won't happen, depending on how our entity list is
  • 0:20 - 0:24
    sorted. The classic solution to this problem is to introduce a z index property
  • 0:24 - 0:29
    to each entity, that describes in what order an object should be rendered. If
  • 0:29 - 0:32
    we assume the map is at z index equal to zero, then our engine will draw
  • 0:32 - 0:36
    entities with lower z indexes first, such that they appear underneath objects
  • 0:36 - 0:42
    with higher z order values. Once we've added the z index value to each of our
  • 0:42 - 0:45
    entities, we have to modify the game engine class's draw function to take this
  • 0:45 - 0:50
    into account. So, looking at the code here, first, our draw function will, of
  • 0:50 - 0:54
    course, go through and draw the map. Then, as before, we walk through each of
  • 0:54 - 0:58
    our entities. And if it's within our viewRect, we render it to the screen. Now,
  • 0:58 - 1:03
    your job is to figure out how to modify this code Sort of we properly reder
  • 1:03 - 1:05
    zindex into account
Cím:
Implementing Z-Ordering - HTML5 Game Development
Leírás:

more » « less
Video Language:
English
Team:
Udacity
Projekt:
CS255 - HTML5 Game Development
Duration:
01:06

English subtitles

Felülvizsgálatok Compare revisions