Outputting an Integer and Manipulating it.

Started by
40 comments, last by Assassin7257 12 years, 3 months ago
i blit the surface too
Advertisement
What do you expect this line to do?:
SDL_BlitSurface( creditString, NULL, screen, NULL);


Or more importantly, isn't this throwing an error at you as well? Because when I look at the SDL reference docs, the first argument of SDL_BlitSurface definitely isn't a std::string...

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

I wasn't getting an error, I just want to know how would I apply it to the screen now ?
If you've had success blitting other surfaces to the screen, you have everything you need. The key points:
1) Turn an integer into a string using stringstream
2) Turn a string into an SDL Surface* using the TTF function.

So if your code still looks like it did in the last big code post, I'd suggest changing that SDL_BlitSurface call from (creditString, ...) to (output, ...) as creditString is your std::string from before, while output is a pointer to a surface (which is what SDL_BlitSurface expects as its first argument).

Hazard Pay :: FPS/RTS in SharpDX (gathering dust, retained for... historical purposes)
DeviantArt :: Because right-brain needs love too (also pretty neglected these days)

std::stringstream ss;
ss << score;
std::string creditString = creditString.c_str();

SDL_Surface* output = TTF_RenderText_Solid(font, creditString.c_str(), textColor);
SDL_BlitSurface (output, NULL, screen, NULL);

apply_surface(150, 150, output, screen);

This is what is looks like and nothing is showing.
One question, are you blitting the text to the screen before or after you blit the background image to the screen?
Before I did it before, now I did after and now random characters show on the screen.
like Ua]ew
Try replacing the line
SDL_Surface* output = TTF_RenderText_Solid(font, creditString.c_str(), textColor);
with
SDL_Surface* output = TTF_RenderText_Solid(font, ss.str().c_str(), textColor);
Okay now its showing on the screen, now if I manipulate would I add 500 to score. Because I'm doing that and it won't work.

This topic is closed to new replies.

Advertisement