hello everybody
today i'd like to ask how would you design a tiled seamless world?
i tried to create one, and so far it's working good.
i have a sf::View, and a slighter greater sf::Rect around it, so I only draw tiles that are inside the Rect before updating the View and drawing it to the screen. something like this:
void GameMap::drawMap(GameSys &game_sys_p){
//get the drawArea (sf::Rect around the View)
int mapX_min = game_sys_p.getDrawArea().left;
int mapX_max = game_sys_p.getDrawArea().width;
int mapY_min = game_sys_p.getDrawArea().top;
int mapY_max = game_sys_p.getDrawArea().height;
//search tiles inside the drawArea
for (int mapX=mapX_min/32; mapX<mapX_max/32; mapX++){
for (int mapY=mapY_min/32; mapY<mapY_max/32; mapY++){
if (tiles_map[mapX][mapY].getType() == 1){
sprite1.setPosition(mapX*32, mapY*32);
game_sys_p.getGameWindow().draw(sprite1);
}
}
}
}
but now i have to put characters in it. and this is a problem, since characters can walk almost on every pixel, and the tiles are drawn only at every 32 pixels. the only way i see to solve it is cycling trough ALL game characters and objects and checking it's positions every frame, to know if they are or not inside the drawArea. but i guess that it will make things too much slow. so i'm here asking the pros for any tips on that: how to optimize a seamless world?
thanks in advance!