I have been working on an SDL Pickin' Sticks game, and the only thing I can't figure out is how to write the number of sticks picked up to the screen.
I'm not sure if I have to use a different function, convert the integer to a string, or what.
Thanks
Drawing integers to the screen in SDL
Moderator: Coders of Rage
- Bullet Pulse
- Chaos Rift Cool Newbie
- Posts: 89
- Joined: Sun Feb 21, 2010 6:25 pm
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Drawing integers to the screen in SDL
Yo, just use the C style 'sprintf' ->
Code: Select all
string sticks_picked;
char temp[16];
sprintf(temp, "Score: ( %i )", player.score);
sticks_picked += temp;
..
Render_Text(sticks_picked);
- Bullet Pulse
- Chaos Rift Cool Newbie
- Posts: 89
- Joined: Sun Feb 21, 2010 6:25 pm
Re: Drawing integers to the screen in SDL
Hmm. When I added that code, it just repeats Score: (0) across my screen, and then after about 10 seconds, it all disappears and doesn't come back up.GroundUpEngine wrote:Yo, just use the C style 'sprintf' ->
Code: Select all
string sticks_picked; char temp[16]; sprintf(temp, "Score: ( %i )", player.score); sticks_picked += temp; .. Render_Text(sticks_picked);
Edit: Okay, I fixed it. It should be
Code: Select all
sticks_picked = temp;
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: Drawing integers to the screen in SDL
You should take a look at stringstreams if you are using C++.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Drawing integers to the screen in SDL
Yeah. The way you're doing it now with sprintf() is the C-style. Not that it really matters, but if you want to take the object oriented C++ route, you probably should have a look at string streams.K-Bal wrote:You should take a look at stringstreams if you are using C++.
-
- Chaos Rift Junior
- Posts: 345
- Joined: Tue Jan 12, 2010 7:23 pm
- Favorite Gaming Platforms: PC - Windows 7
- Programming Language of Choice: c++;haxe
- Contact:
Re: Drawing integers to the screen in SDL
Code: Select all
std::string Utilities::NumberToString(float number)
{
std::stringstream out;
out << number;
return out.str();
}
std::string Utilities::NumberToString(int number)
{
std::stringstream out;
out << number;
return out.str();
}
std::string Utilities::NumberToString(double number)
{
std::stringstream out;
out << number;
return out.str();
}