Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Depth sorting

Depth sorting, or z-sorting, is something we've already discussed in Chapter 15, when you were just applying perspective to sprites. In that case, you sorted the array of sprites (actually subclasses of Sprite that had 3D properties) by their zpos property.

At this point however, you are not dealing with multiple sprites. All of the polygons are being drawn within the same graphics object of the main document class. Thus, whenever a particular polygon is drawn, it will be drawn on top of any that have been drawn earlier. So, rather than swapping anything's depth, you just need to determine which polygon gets drawn when. Specifically, you want to draw the ones that are farthest away first; then you draw the rest, working your way forward, so that the closest polygons are drawn last, covering anything they might be in front of.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial