Jump to content
  • Advertisement
Sign in to follow this  
tgashby

SDL: Moving images and cleaning up their left-overs

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

Hello folks,

I am working on a game right now, (gee aren't we all ;-) ) and I was hoping to get some guidance.

I am new to SDL and I think I have the hang of it, but I did have one question.

I have a player that moves around the screen, and now enemies that attempt to "get" you.

My question is this: What is the efficient way to move the images of these different objects and clean up the old pieces of the image left over. For example, when the enemies move to attack, they leave behind their old images.

What I am doing right now is re-drawing the square of the level image where the enemy was before it moved. But I feel like just putting more and more images on the display surface is going to cause some serious performance issues. I have also started just filling in the tiny rectangles left over rather than the entire rectangle, but still I am putting more and more images on the display surface.

Am I missing something really obvious about SDL?

Thank you,
Tag

Share this post


Link to post
Share on other sites
Advertisement
Quote:
But I feel like just putting more and more images on the display surface is going to cause some serious performance issues.
That's not how it works. The display surface is simply an array of bytes, with each pixel represented by a fixed number of bytes. Drawing an image to the display surface just replaces what's there; the images don't 'accumulate' in any way. Or maybe that isn't what you mean?

Anyway, what you're doing sounds fine (in principle). The two most common approaches are a) erase the whole screen every frame and redraw from scratch, or b) use a 'dirty rectangle' approach, as you're doing currently. The former is the usual approach when using hardware-accelerated graphics, while the latter may be more appropriate when using software blitting.

(Also, these issues aren't really specific to SDL - they're just general issues related to rendering, and rendering in software in particular.)

Share this post


Link to post
Share on other sites
Thank you.

I did think that they accumulated. That's was my fear.

Thank you for the help. I knew that the rendering thought process was across engines, but I had the question specifically for SDL :-P.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!