35
« on: June 21, 2012, 10:13:44 pm »
I'm also working on a similar project. Assuming that you have a player centered on the screen, the render algorithm should go something like this.
define tileResolutionX as the number of tiles per row
define tileResolutionY as the number of tiles per column
define screenResolutionX as the width of the window you are rendering to
define screenResolutionY as the height of the window you are rendering to
xOffset = player.x - floor(tileResolutionX / 2) -> This will center the map around your player's x-position
yOffset = player.y - floor(tileResolutionY / 2) -> This will center the map around your player's y-position
for x = 0 to tileResolutionX -1
for y = 0 to tileResolutionY - 1
render tile(x + xOffset, y + yOffset) at (x * (screenResolutionX / tileResolutionX), y * (screenResolutionY /
tileResolutionY)) -> This keeps all sprite sizes relative to one another and renders them relative to the player
end for
end for
You can replace the resolutions with literals if you don't plan on changing the window's size during the execution of the program.
Hopefully this helps.