I have a basic 20x20 array that stores the map for my game. It either has a 1 or 0 to say a path and a non path. When I draw it on the screen, It seems to take to long to draw one at a time and looks like a snake is being loaded on the screen. I need them drawing faster.
Set up the screen array
for(int i=0; i<sizeOfArray; i++)
{
for(int j=0; j<sizeOfArray; j++)
{
if (LevelOne[i][j]==0)//Path
{
screenChunks[i][j].Set(i*40,j*40,"Path.bmp", screen);
}
if (LevelOne[i][j]==1)//Wall
{
screenChunks[i][j].Set(i*40,j*40,"Wall.bmp", screen);
}
if (LevelOne[i][j]==2) //Hero
{
screenChunks[i][j].Set(i*40,j*40,"Hero.bmp", screen);
}
}
}
Draw the sprites
for(int i=0; i<sizeOfArray; i++)
{
for(int j=0; j<sizeOfArray; j++)
{
screenChunks[i][j].Draw();
}
}
//Dynamically drawn each time
SDL_FillRect(screen,0,0);
//Hero Start Position
hero.Draw();
SDL_Delay(60);
Sprite.cpp Draw Method
void Sprite::Draw()
{
SDL_Rect offset;
//Give the offsets to the rectangle
offset.x = PosX;
offset.y = PosY;
//Blit the surface
SDL_BlitSurface( sprite, NULL, Screen, &offset );
Height = offset.h;
Width = offset.w;
SDL_UpdateRect(Screen, 0,0,0,0);
}
Sprite Setter
void Sprite::Set(int posX, int posY, string imagePath, SDL_Surface *screen)
{
PosX = posX;
PosY = posY;
ImagePath = imagePath;
Screen = screen;
if(ImagePath == "")
return;
char * writable = new char [ImagePath.size()+1];
strcpy (writable, ImagePath.c_str());
temp = SDL_LoadBMP(writable);
sprite = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
// free the string after using it
delete[] writable;
}