I have successfully stored and drew 4Regions of 25x25Tiles to screen and made camera to move around screen
Here is my function
But what i need is to draw only tiles that are on screen.
I am trying to save performance, cause i want to be efficient
Ani tips or hints would be userfull
Here is my function to draw all 4 region to screen;
void Area::DrawArea(int CamX, int CamY, App* obj_App)
{
int TileID = 0; //Holds TileID;
int RegionID = 0; //Holds RegionID
int surfW = ((*GETP_surf_Tileset())->w / TILE_SIZE); //For SDL_Rect crop
SDL_Rect crop,pos;
crop.w = TILE_SIZE;
crop.h = TILE_SIZE;
(*obj_App->GETP_surf_Screen());
for(int a = 2; a < 6; a++) /*HomeMade math to draw to correct position will went : "x= 0 y = 0", "x = 1, y = 0", "x = 0 y = 1", "x = 1 y = 1"
So we draw to correct place to screen*/
{
for(int y = 0; y < REGION_SIZE/*25*/; y++)
{
for(int x = 0; x < REGION_SIZE/*25*/; x++)
{
if(RegionList[RegionID].TileList[TileID].Layer1 == -1) /* Check if tile loaded failed */
{
TileID++;
continue;
}
crop.x = (RegionList[RegionID].TileList[TileID].Layer1 % surfW) * TILE_SIZE;
crop.y = (RegionList[RegionID].TileList[TileID].Layer1 / surfW) * TILE_SIZE;
pos.x = (x * TILE_SIZE) - CamX + ((a % 2) * 1000);
pos.y = (y * TILE_SIZE) - CamY + (((a-2) / 2) * 1000);
SDL_BlitSurface(surf_Tileset, &crop, *obj_App->GETP_surf_Screen(), &pos);
TileID++;
}
}
TileID = 0; //We set TileID to 0 for next RegionLoop
RegionID ++; //We increment Region for next loop so we draw correct tiles
}
}