drawing the "visible" region
i have no trouble drawing my tiles in the isometric perspective. i draw them in this order:
1
4 2
7 5 3
8 6
9
if this little map fits on the screen, then all is well. however, when i want the map to be larger than the screen, such that the map must be scrolled as the player walks around, i am at a loss. a couple of solutions might be:
1. draw the entire map (at least the base tiles like grass, sand, dirt) into one really large offscreen buffer. then, pull out a rect the same size as the screen that is centered around the "active" player. if the player moves, then move the "viewing rect" by as many pixels. in this case, i am not really working with map coodinates at all, but pulling out a rect of pixels from the large offscreen buffer. thus, putting objects in their correct spot seems tricky?
2. draw the viewing area on the fly. if the tiles were square, this would be easy; simply calculate:
numberotileswide = screenwidth/tilewidth
numberotileshigh = screenheight/tileheight
then, draw numberotileswide and numberotileshigh from a starting map position. that starting position could be set to keep the player centered. in an isometric game, the tiles are diagonal and not lined up straight so it ain''t as simple. however, it would be easier to figure where to put trees and other "objects of height" since this approach works with map coodinates and not really screen coodinates.
what is the best way to draw the "visible region" (ie that region of the map that gets drawn to screen)? i am writing this game on a mac, so pc-specific code gets puzzling. however, this problem is general enough that it should be encountered by isometrists from every platform.
I''ve gotten this question several times. I won''t be able to fully answer it here, but hopefully I''ll give you enough information about how to solve the problem to get you started (this exact problem takes up two entire chapters of my book--about 45 pages or so)
i''m going to assume that you have a method of converting from screen coordinates into map coordinates, either through a mousemap or some other method. if you dont, go and learn how to do that, then come back. i''ll wait.
the way you want to render an isometric map is in horizontal rows of tiles. the first thing you need to do is take the corners of the screen (or the portion of the screen that you are displaying) and determine what map locations they lie on (if you are using a mousemap, you need to determine the CENTRAL tile within that map, not one of the corners). from there, move one tile diagonally away from the screen (i.e. for the upper left corner, move one tile northwest, for the upper right corner, move one tile northeast)
after that, you probably want to move the left side corners an additional tile to the west, and the bottom corners an additional tile to the south.
from here, you render in strips, from the upper left to the upper right, moving one tile to the east with each step.
after an entire row has been rendered, you move the upper left and upper right corners down. if you have rendered an odd number of rows, move the corners diagonally "inward". if you have rendered an even number of rows, move them outward. continue rendering rows of tiles until the upper left and upper right corner are the same as the lower left and lower right corners.
the code for doing this is pretty complex, but well worth it, as it''ll take the same amount of time to render a screen full of tiles no matter how big the tile world is.
unfortunately, i can''t fully explain this in just a short little messageboard post. my book comes out next march, so pick it up and read chapters 16 and 17, they explain all about this. the book is primarily for the PC, but the algorithms i talk about are generic enough that you should be able to convert them to your platform.
i''m going to assume that you have a method of converting from screen coordinates into map coordinates, either through a mousemap or some other method. if you dont, go and learn how to do that, then come back. i''ll wait.
the way you want to render an isometric map is in horizontal rows of tiles. the first thing you need to do is take the corners of the screen (or the portion of the screen that you are displaying) and determine what map locations they lie on (if you are using a mousemap, you need to determine the CENTRAL tile within that map, not one of the corners). from there, move one tile diagonally away from the screen (i.e. for the upper left corner, move one tile northwest, for the upper right corner, move one tile northeast)
after that, you probably want to move the left side corners an additional tile to the west, and the bottom corners an additional tile to the south.
from here, you render in strips, from the upper left to the upper right, moving one tile to the east with each step.
after an entire row has been rendered, you move the upper left and upper right corners down. if you have rendered an odd number of rows, move the corners diagonally "inward". if you have rendered an even number of rows, move them outward. continue rendering rows of tiles until the upper left and upper right corner are the same as the lower left and lower right corners.
the code for doing this is pretty complex, but well worth it, as it''ll take the same amount of time to render a screen full of tiles no matter how big the tile world is.
unfortunately, i can''t fully explain this in just a short little messageboard post. my book comes out next march, so pick it up and read chapters 16 and 17, they explain all about this. the book is primarily for the PC, but the algorithms i talk about are generic enough that you should be able to convert them to your platform.
Get off my lawn!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement