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

Author Topic: Scrolling Text in Views  (Read 2968 times)

0 Members and 1 Guest are viewing this topic.

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Scrolling Text in Views
« on: October 20, 2014, 11:24:31 pm »
Hi Folks,

I have a view that takes up 30% of the window in the y axis, i.e. basically it is a lower view that displays messages/updates as the game progresses.

I have a string that increases with game messages in the game loop, i.e. in a basic form it is as below.


sf::Text text;
string msgStr;

while (true)
{
         window.clear();
        msgStr += "New game update\n";
        text.setString(msgStr);

         window.setView(lowerView);
        window.draw(text);
        window.display();
}
 

So as you can see the text keeps increasing and it soon goes off the view's screen. So what I want to do is add an if statement to check if the lower y position of the sf::Text entity has gone off-screen.  i.e.:-

if (sf::Text.bottom-Y pos > view.y-size)
{
               lowerView.move(0,30);
}

 

However I'm not sure on how to retrieve those two bits of information. So is anyone able to advise on the below 2 questions.

(1) How to get a sf::Text entities bottom(y),left or bottom(y), right position? Basically with each addition of a string with a \n, then the y position of the sf::Text should increase, right? So how can I get this information?

(2) How do I get the view's x and y size, so I can check if the sf::Text's y position has gone off-screen? (in my example I only really need the y size, however I assume I can get the x size as well somehow?)

Many thanks in advance.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Scrolling Text in Views
« Reply #1 on: October 20, 2014, 11:29:31 pm »
A quick visit to the official docs leads me to believe you may be interested in sf::Text::getLocalBounds()/getGlobalBounds() and sf::View::getSize().

By the way, did you try searching the documentation before posting?

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: Scrolling Text in Views
« Reply #2 on: October 20, 2014, 11:51:13 pm »
For the sf::Text, I went to here http://sfml-dev.org/documentation/2.0/classsf_1_1Text.php and found getPosition() but that seemed to return the top left position. Obviously I completely missed those other member functions.

For the views, no I was using one of the 2.0 tutorial (http://sfml-dev.org/tutorials/2.0/graphics-view.php) which doesn't mention getsize(). Obviously I should have checked the reference page.

Anyway, thanks for pointing me to those functions.

 

anything