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 - Quilty

Pages: [1]
1
Window / Re: How to display numbers in a window?
« on: June 28, 2012, 01:16:01 am »
I'll definitely try and do that. Thanks for the links and all the help. :)

2
Window / Re: How to display numbers in a window?
« on: June 28, 2012, 12:58:13 am »
Thank you very much for your help! I'll be sure to use the proper tags in the future.

The code you suggested works, but now each number is being drawn over the previous one, so if you can imagine 1000, 1200 etc. all jumbled one over the other. I was hoping that each number would get replaced by the next one. Perhaps there is a way to achieve that? Is there maybe a way to delete the first number and then display the next one as soon as the button is clicked?

3
Window / Re: How to display numbers in a window?
« on: June 28, 2012, 12:08:31 am »
I tried writing a code. The purpose of it is to display a number on the screen, and then every time a part of the screen is clicked the number is increased by 100. However, this doesn't seem to work, so if you could help me out with this, I'd be grateful.  :)

#include <SFML/Window.hpp>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <SFML/Graphics.hpp>

void HandleMouseClick(sf::Mouse::Button click, int x, int y);


int game = 1000;


int main()
{

       
    sf::RenderWindow window(sf::VideoMode(1024, 768), "My window");
       

        sf::Text mytext;
        std::stringstream ss;  // #include <sstream>
        ss << game;
        mytext.setString( ss.str().c_str() );
        window.draw(mytext);

        window.display();
       

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            if(event.type == sf::Event::MouseButtonPressed)
                HandleMouseClick(event.mouseButton.button, event.mouseMove.x, event.mouseMove.y);
                                       
                        // "close requested" event: we close the window
            else if (event.type == sf::Event::Closed)
                window.close();
        }
       
        }

        return 0;

        }

void HandleMouseClick(sf::Mouse::Button button, int x, int y)
{
       if(x >= 0 && x < 1023 && y >= 145 && y < 380)
        {
            game = game + 100;

        }

}

4
Window / Re: How to display numbers in a window?
« on: June 26, 2012, 11:44:15 pm »
Thank you for your suggestions!

I found the following code, but I'm not sure it's the best for SFML 2.0. Other users suggested some other code, but I found this one to be easiest to understand, and it seems to work fine in 2.0.


int score = 123456; // the score to print

sf::Text mytext;
std::stringstream ss;  // #include <sstream>
ss << score;

mytext.setString( ss.str().c_str() );
   

window.draw(mytext);

5
Window / How to display numbers in a window?
« on: June 26, 2012, 08:47:00 pm »
Hi everyone :)

I am using SFML 2.0 with Visual Studio 2010 and trying to display some numbers in a window. I want the window to read a certain integer value (int number) and to display this number every time I press a button in the window. However, I want to link this button to a command that states int number = number + 1. Basically the window should update the number every time the button is clicked. I'm not sure if I should use pointers, and I'm a beginner in C++.

I hope you can help me.  :)

Pages: [1]