• Advertisement
Sign in to follow this  

SDL Question

This topic is 2106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my work around but it makes my program so slow

[code]
// 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");
[/code]

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...

[code]
// 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;
[/code]

Also the apply_surface function is from [url="http://lazyfoo.net/SDL_tutorials/lesson06/index.php"]http://lazyfoo.net/S...son06/index.php[/url]

Share this post


Link to post
Share on other sites
Advertisement
If you just want to copy the surface you can use SDL_DisplayFormat (or SDL_DisplayFormatAlpha)
[code]tile = SDL_DisplayFormat(temp_tile);[/code]

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.
[code]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);[/code]

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.

Share this post


Link to post
Share on other sites
Thank you, Thank you, Thank you :D
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! :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement