Archived

This topic is now archived and is closed to further replies.

viper716

Displaying the score???

Recommended Posts

Ok I’m using DrawText to display the Score, it only allows you to display strings. How do you convert a integer value to a string? I’m sure I’ve done this before only I’ve completely forgot. Using C++, Windows Environment.

Share this post


Link to post
Share on other sites
Or stringstreams. They're somewhat more convenient, I think.


#include <sstream>
...
std::stringstream str;
str << iScore;
DrawText(str.str().c_str());




[edited by - micepick on May 28, 2003 4:05:02 PM]

Share this post


Link to post
Share on other sites
Ok when I said windows environment i meant dialog based. None of those two work. The include file stringstreams isn''t recognised unless you mean cstring? It also doesn''t like sprintf.

Also what’s the i for?

thanks

Share this post


Link to post
Share on other sites
For std::stringstream you should include sstream, as in:

#include <sstream>

It should then work. The 'i' part of the variable name is just to show you that it is an int (integer). You do not have to name it this, it just adds clarity to the example.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on May 28, 2003 4:05:44 PM]

Share this post


Link to post
Share on other sites
A RGB color encoded in a COLORREF has a trivial format in hexadecimal:

0x00BBGGRR

where BB, GG, RR are intensities of each color, from 00 to FF.
The brightest green is then 0x0000FF00.

Share this post


Link to post
Share on other sites
Ok I have two new problems now

How do I space out the text I have on the same line? i.e
Score: 230

Here’s what I’ve got:
dc.DrawText(("SCORE: "),-1,&m_WinRect,DT_SINGLELINE);
dc.DrawText((str.str().c_str()),&m_WinRect, DT_SINGLELINE);

Also how do I update the score? The variable does seem to be working only the DrawText isn’t updated it. I figured maybe you keep redrawing it but that doesn’t work.

Any Ideas?

Thanks
I''ll get there soon

Share this post


Link to post
Share on other sites
quote:

How do I space out the text I have on the same line?


#include <sstream>

std::stringstream ss;
ss << "Score: " << iScore;

dc.DrawText(ss.str().c_str(), ...);

quote:
Also how do I update the score?

I haven't used DrawText() before, but I would guess that you redraw it in the update part of your main game loop.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on May 28, 2003 6:23:02 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by micepick
0x00BBGGRR
Isn''t that supposed to be 0x00RRGGBB ? I just wrote an image processing program and I remember that I did >> 16 to extract the red value.

Share this post


Link to post
Share on other sites
quote:
Original post by alnite
Isn't that supposed to be 0x00RRGGBB ? I just wrote an image processing program and I remember that I did >> 16 to extract the red value.


I thought so too, but I looked it up on MSDN. Apparently, the GDI uses BBGGRR.

[edited by - micepick on May 28, 2003 7:16:17 PM]

Share this post


Link to post
Share on other sites