Jump to content
  • Advertisement
Sign in to follow this  
Adam4444

Write current score to screen (SDL question)

This topic is 4326 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 there. I'm have recently made my second game. Everything works just fine except one thing. I want to write out the score the player currently have. But everytime the score increases and I write it out again it just writes over the old one. So for example if the score was 12 first and then it increases to 23 it just puts 23 over 12 so one can't se what it says. How shall I solve that problem? Here's the relevante code:
score_str = malloc(sizeof (char) * (7 + score));
sprintf(score_str, "Score: %ld", score);
text_surface = TTF_RenderText_Solid(font, score_str, (SDL_Color) {255, 255, 255});
src_rect.w = dest_rect.w = text_surface->w;
src_rect.h = dest_rect.h = text_surface->h;
src_rect.x = src_rect.y = dest_rect.x = 0;
dest_rect.y = HEIGHT;
SDL_UpdateRect(text_surface, 0, 0, text_surface->w, text_surface->h);
SDL_BlitSurface(text_surface, &src_rect, display_surface, &dest_rect);
SDL_UpdateRect(display_surface, 0, 0, 0, 0);
free(score_str);

Share this post


Link to post
Share on other sites
Advertisement
You must "erase" the previous score which was drew in the screen before repaint the new score. Just blit the portion of background behind the score drew in the screen surface -essentialy erasing it- and then blit the new score surface. If you are using a flat color as background just repaint the portion with that color.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zheo
You must "erase" the previous score which was drew in the screen before repaint the new score. Just blit the portion of background behind the score drew in the screen surface -essentialy erasing it- and then blit the new score surface. If you are using a flat color as background just repaint the portion with that color.


Oh how stupid of me. Why didn't I thought of SDL_FillRect(). :S
Thanks, however.

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!