Sign in to follow this  

What should I do with enemy after it is killed? (C++ and SDL)

This topic is 3552 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

Hi, i need some help here, I'm an extreme beginner. I'm making a game with SDL, and in it you shoot enemies, and when you shoot them enough times they die. My program can recognize when the enemy dies and I have it so that it only blits the enemy if they are alive, so that once they die their surface isn't being blitted anymore and it looks like they're gone. of course, even though you can't see them, the surfaces are still there, and they're causing my game to lag. How do I actually get rid of the surface completely when they get killed? Someone mentioned freesurface but i didnt understand how and where to use it. I have all my surfaces and rectangles being declared at the start of my .cpp file. I will also need to use this same surface on all the other levels of the game. What do I do with the surface when it isnt being used? Thanks!

Share this post


Link to post
Share on other sites
yes, i don't use SDL so i dont know what command you are using for blitting or whatever, but theres no reason to have the same data loaded twice.

Share this post


Link to post
Share on other sites
Quote:
i load the same bmp to both surfaces... but i could have 2 enemies on one screen using one surface?

Yes. How you go about doing it is up to you (global surfaces, pointers, arrays, whatever) but when you blit a surface (I'm assuming you have a separate function or class to do this. If not, you should) you should include an argument that specifies which surface to blit.

If you haven't already, i strongly recommend you check out this site.

To answer your question about SDL_FreeSurface, what it essentially does is erases a surface from memory. It's commonly used to clean up when a game is ending, or when a surface is no longer needed (for instance, once it's been copied to another surface). In your specific case, you really shouldn't be saving the same surface multiple times when you can save it once and use it multiple times, but it would be used when an enemy dies to erase that enemies' surface.

Share this post


Link to post
Share on other sites
I found where your issue is


if (es1right == 1 && soldier1 != SDL_LoadBMP("graphics/esright.bmp") && es1dani == 10 && es1ducking == false && es1active == true)

Every time you run an if statement like this it loads graphics/esright.bmp and it just remains in memory, my question is why you're doing this among a whole bunch of other questions, so all I'm going to say is check your e-mail

Share this post


Link to post
Share on other sites

This topic is 3552 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this