SDL_Rect marco; SDL_Rect coordenadas; //Marco is "frame", the method I use to select the blitable part of the bitmap. Coordenadas is "Coordinates", the place where everything will be. SDL_Surface *objeto=NULL; //Objeto is what I´ll blit into "pantalla", the screen surface. objeto=CargarImagen("juego.bmp"); marco.w=16; marco.h=16; for(short int contador=0; contador<1200; contador++) { switch(matriz[contador]) //Matriz is the game matrix. { case 0: marco.x=0; marco.y=0; break; case 1: marco.x=48; marco.y=0; break; case 2: marco.x=48; marco.y=16; break; case 3: marco.x=16; marco.y=0; break; case 4: marco.x=32; marco.y=0; break; case 5: marco.x=32; marco.y=16; break; case 6: marco.x=0; marco.y=16; break; } coordenadas.x=((contador%40)*16)+80; //This is the way I get the coordenadas.y=((contador/40)*16)+48; //coordinates. SDL_BlitSurface(objeto, &marco, pantalla, &coordenadas); }
Here, this function loads the tileset and checks the whole matrix. Depending on the value of the matrix a certain portion of the tileset is blitted.
The function is called in each gametic (errr... Every iteration of the main game loop, whether something happens or not... I know, lazy!). You can see that I use a "CargarImagen" function (literally "Loadimage") so each time I run the function I load the bmp file again. What I don´t do is loading the bmp for each blitting "tile" of the matrix.
So, do you advise me to load the bmp file only once?. I could load it in the "main game loop" and send the resulting surface along to the function above like maindrawing(pantalla, objeto)... I could also make it a global surface but I´m not sure about globals (I don´t really dig them, not sure why).
Thanks in advance for all replies and suggestions :).