Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem Drawing Text  (Read 1379 times)

0 Members and 1 Guest are viewing this topic.

Bicepz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problem Drawing Text
« on: June 17, 2011, 04:10:41 am »
I'm trying to draw the fps for my game using sf::Text and sf::Clock.

Here is my code:

Code: [Select]

float Framerate = 1.f / rWindow.GetFrameTime() * 1000;
float time = timer.GetElapsedTime();
std::stringstream ss;
ss << "FPS: " << Framerate << "Time: " << time;
std::string fRString = ss.str();


if(time > 2000.f)
{
text.SetString(fRString);
timer.Reset();
}

ss.str("");
text.Move(View2.GetCenter().x - (View2.GetSize().x / 2 - 1), View2.GetCenter().y - (View2.GetSize().y / 2 - 1));


With sf::Text text and sf::Clock timer declared outside of the game loop.
This does not work. I can see the text get drawn once and than never again.

 If I move the sf::Text text to be constructed within the game-loop instead of main it works. What am I doing wrong? Timer still works outside of the game loop so I guess I am just missing something. I'm obviously trying to construct my text outside of the game loop to capture fps and stop it from updating every frame, with it in the loop it just updates to fast to read.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Problem Drawing Text
« Reply #1 on: June 17, 2011, 01:02:10 pm »
Are you using sf::Clock with seconds or milliseconds?

Code: [Select]
if(time > 2000.f)Why the float suffix? Milliseconds are integral in SFML. So either use 2000 (new sf::Clock) or 2.f (old sf::Clock).

Code: [Select]
text.Move(...)Shouldn't you call sf::Text::SetPosition() here?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Bicepz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Problem Drawing Text
« Reply #2 on: June 17, 2011, 01:48:22 pm »
Those were good points and you solved my problem. The issue was the move instead of using set position. Originally it worked because I was re-constructing the text every loop.