How to Reload A Surface? |
Nathaniel J Fries
|
You don't want to "reset" the surface each time. Instead, keep text in its own surface, and background in its own surface. Blit background surface to screen first, then text.
IE:
|
|||||||||||||
|
Nathaniel J Fries
|
As for why your first solution did not work, it is because you had it backwards.
If surface1 is just the loaded image, and surface2 is the image plus text, then you want to blit surface1 to surface2 to reset it (assuming no colorkey/alpha). Your second solution would not work because it would make both surfaces use the same memory for pixels. This is because SDL_Surface is a plain C struct, which happens to contain a pointer to where pixel data is; assigning one SDL_Surface to another SDL_Surface will make this pointer equal. This attempted solution also results in a memory leak (the memory holding the pixels for surface2 would be lost), which is a serious and often hard-to-find bug. While SDL is really good for learning 2D graphics programming, you need to learn how to use C before you can really take advantage of it. |
|||||||||||
|
Ironic
|
Thank you so much for your help! It seems so obvious in hindsight! I am going to go and try this right now!
You are correct of course. I am trying to learn "by doing", and if I can finish the small project I am working on right now it will really help out some deserving people. Sometimes though I just cannot figure out a way forward, I really cannot express how grateful I am that you took the time to help. |
|||||||||||||||
|