Jump to content
  • Advertisement
Sign in to follow this  
russt17

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

This topic is 3772 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
Advertisement
SDL_Surface *soldier1

for the surface, and then

SDL_Rect *soldier1_info

for the rectangle, if thats what you mean by data structure.

Share this post


Link to post
Share on other sites
Remember that you probably don't need a separate surface for each enemy if you are using the same graphics for both.

Share this post


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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!