Skip to main content
gamedev.net
🔒 Locked

SDL Question

Started by LatchGameDev 1 reply 1.7k views
Original Post
LatchGameDev
LatchGameDev
This is my work around but it makes my program so slow


// I take the small square tile i want out of the tile_sheet and blit it onto temp_tile
apply_surface( 0, 0, tile_sheet, temp_tile, &clip);

// I save the SDL_Surface as tile.bmp
SDL_SaveBMP(temp_tile, "Graphics\\tile.bmp");

// Lastly I load the bmp into a different SDL_Surface called tile
tile = load_image("Graphics\\tile.bmp");


Like I said the above works but is so darn slow. Ideally what I'd like to do is set the clipped part of tilesheet into a seperate SDL_Surface and have it save like...


// I take the small square tile i want out of the tile_sheet and blit it onto temp_tile
apply_surface( 0, 0, tile_sheet, temp_tile, &clip);

tile = temp_tile;


Also the apply_surface function is from http://lazyfoo.net/S...son06/index.php
Wooh
Wooh
If you just want to copy the surface you can use SDL_DisplayFormat (or SDL_DisplayFormatAlpha)
tile = SDL_DisplayFormat(temp_tile);

If you don't want to use temp_tile at all you could just create a new surface with the same format as tile_sheet and blit the part you want.
tile = SDL_CreateRGBSurface(tile_sheet->flags, clip.w, clip.h, tile_sheet->format->BitsPerPixel, tile_sheet->format->Rmask, tile_sheet->format->Gmask, tile_sheet->format->Bmask, tile_sheet->format->Amask);
apply_surface( 0, 0, tile_sheet, tile, &clip);


Copying/creating surfaces are slow so try to avoid doing it each frame update. If you only do it at loading/setup time it shouldn't be a problem.
LatchGameDev
LatchGameDev
Thank you, Thank you, Thank you
I'm only copying surfaces when i'm loaded/reloading the map and it was taking 44 seconds to load my map before. I used your first suggestion and it reduced the time to less then a second!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.