Jump to content
  • Advertisement
Sign in to follow this  
negflar

Update the screen when moving

This topic is 4580 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 have a question about updating the screen during an animation. I have a main surface called screen. Another that i use for background and the last, for animated prite. I apply background surface and sprite surface with SDL_BlitSurface to main surface. When i move the sprite around the screen, i redraw (with SDL_Blit surface) in a different position. Obviously, the old position are still visible. The only way that i have found to fix that is to reblitting also the background before i reblit the sprite surface. It is a good solution? My question is if exist another way to refresh the backgorund without having to reblit it. Tank's

Share this post


Link to post
Share on other sites
Advertisement
You can re-blit just the square where the srpite was last. This will save you from having to do the entire screen. Since you already have access to the background and are doing the redraw anyway. It should be just a simple to only refresh behind the one sprite. This will increase your performance when you start have multiple sprites on the screen.

Although it also depends on the target device and the complexity of the game, or program. Depending on what you are try to accomplish your soltion may be good enough.

I hear premature optimization is the root of all evil, so if it becomes an issue you now have a soltion to work with.

I wrote a simple game a while back for a mobile phone, and I did end up using this technique in the end.

However if the whole screen is going to be covered in sprites, this maqy not be the best solution. Since you will be doing extra calculating and prety much redrawing the whole screen anyway.

Share this post


Link to post
Share on other sites
You can use SDL_UpdateRect (I think) to do "dirty rect" updating -- just be very careful if you have to scroll.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matsy
You can re-blit just the square where the srpite was last. This will save you from having to do the entire screen. Since you already have access to the background and are doing the redraw anyway. It should be just a simple to only refresh behind the one sprite. This will increase your performance when you start have multiple sprites on the screen.


Yes, i have already tried this solution and i think that is a very good solution. But i have another question. If i have two sprite and one go over the other, how can i manage this? I have not understand if when i move a sprite, and i re-blit the background (or only a square of background) in effects i really delete the part of background, or i only overwrite a part of screen (and so the old part of screen is still present but it is hidden from the new blit.
And so it is possible to really delete a part of a surface that i have previously blited and view the part that was hidden?

Tank's

Share this post


Link to post
Share on other sites
It's actually easier to just redraw the whole screen all over again. Considering the small scale of the applications you'll be doing, the computer won't have any problems doing so. What happens later on in development when you want to move the camera over by a pixel? You'll still be redrawing the whole screen away. All of the current generation advanced 3D games redraw the screen every frames, so I doubt your computer will have troubles drawing a simple 2D SDL application.

Share this post


Link to post
Share on other sites
Might I ask what project you're working on? As others have mentioned, unless you're working on a very constrained platform like a cell phone or PDA, you really don't need to worry about this stuff. Just redraw the background every frame; it's quite simple. Why worry about optimization when (as near as I can tell) you're just getting started on your program?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ok, many thanks to all. You have cleared me many doubts.

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!