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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Crown

Pages: [1]
1
General / Re: Moving sf::Text using setPosition inconsistent amounts
« on: August 06, 2014, 09:53:14 pm »
Thank you for taking the time to get back to me, I really appreciated it.  I made the change and it works now.

Now, to understand this correctly, when I am setting the position, it sets the position of the origin?  But, getLocalBounds() returns the bounding box of the string text within the sf::Text?  The top left coordinates of this local bounds is therefore NOT the origin of the sf::Text?  How are these local bounds calculated?  Are they changing every time the string of the text changes?  I'm sure there is a reason, so why is the top left of the bounding box not at the origin?

Edit: Upon closer look at the documentation I see that there is also a getPosition() function which I assume then get's the global origin.  Another solution to the two above would then be: txtMovable.getPosition().y - 10.

2
General / Moving sf::Text using setPosition inconsistent amounts
« on: July 31, 2014, 08:29:44 pm »
Hello, I am trying to dynamically position a sf::Text up and down based on keyboard input.  The problem is, when I set the position by incrementing its location, I get different values of movement when I move it up or down even if I increment/decrement by the same amount.  Here is a simple version:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "Move Text Test");
        sf::Font fontMovable;
        fontMovable.loadFromFile("arial.ttf");

        sf::Text txtMovable;
        txtMovable.setFont(fontMovable);
        txtMovable.setString("Testing");
        txtMovable.setColor(sf::Color::White);
        txtMovable.setCharacterSize(20);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
                        if (event.type == sf::Event::KeyPressed)
                if(event.key.code==sf::Keyboard::Up){
                                        txtMovable.setPosition(txtMovable.getGlobalBounds().left, txtMovable.getGlobalBounds().top - 10);
                                }else if(event.key.code==sf::Keyboard::Down){
                                        txtMovable.setPosition(txtMovable.getGlobalBounds().left, txtMovable.getGlobalBounds().top + 10);
                                }
        }
        window.clear();
        window.draw(txtMovable);
        window.display();
    }
    return 0;
}
 

As you can see, I increment by 10, but when I move the sf::Text up, it actually goes up by 5 and going down actually goes down by 10.  These numbers change based on the size of the font.  I know there is probably something I am not understanding about the getGlobalBounds().

I am using SFML 2.1 and Visual C++ Express 2010.

Any help would be appreciated.   Thanks.

3
Network / Re: SocketSelector within gameloop
« on: January 25, 2014, 06:19:05 am »
Thanks Azaral, I was hoping to avoid multi-threading.  I haven't really done multi-threading before but I guess I'll have to bite the bullet and figure it out.

4
Network / SocketSelector within gameloop
« on: January 25, 2014, 01:12:22 am »
I don't want to have a separate program for client and server so I have made my main game loop with a switch that determines if the process is running in server or client mode.  The rest of the game is, of course, the same.  The problem is that the SocketSeletor::Wait() on the server portion blocks the program flow. 

What I have done is set the timeout to very low, I think 20 milliseconds, which allows my server process to run fine at 30fps.  My game isn't processor intensive and so I won't have to worry about slowing the framerate that way.  Is this an appropriate way to solve this problem?  If I'm making a game in the future that can't wait around 20 milliseconds, what should I do?  Is there a lower limit on this?  Can I wait just 1 millisecond?

Thanks.

Pages: [1]