[SDL] correct way of map scrolling
Stefan Hendriks
stefanhen83 at gmail.com
Fri Aug 10 01:35:51 PDT 2007
>
> But it looks like you're using a full pre-rendered map instead of
> something generated more dynamically, so that wouldn't work as well
> for you.
Who said i was drawing everything and then move the viewport?
I'd say, use the viewport to know what to draw, and then calculate the
tile x and y positions accoring to your camera positions.
The only question that remains is :
- is the camera X,Y position pixel per pixel
or:
- is it per tile?
Ie, tilesize = 32 pixels;
More likely in pseudo code:
Map tiles[x][y];
void draw_tile(tile , x, y) {
int drawX = x - cameraX;
int drawY = y - camerayY;
blit(screen, drawX, drawY);
}
// this draws tiles per tile:
for (int x = cameraX; x < screenwidthXinTiles; x++) {
for (int y = camerayY; y < screenwdithYinTiles; y++) {
draw_tile(tiles[x][y],
}
}
// and this by pixel:
for (int x = (cameraX / 32); x < screenwidthXinTiles; x++) {
for (int y = (camerayY / 32); y < screenwdithYinTiles; y++) {
draw_tile(tiles[x][y],
}
}
--
Stefan Hendriks
-----------------------
http://www.fundynamic.nl
More information about the SDL
mailing list