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

Author Topic: Output Flashes When I Type  (Read 3237 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Output Flashes When I Type
« on: August 15, 2010, 03:22:37 pm »
Whenever I type in a number for the input in my program, it flashes onto the screen whenever I hit a number (I've not allowed it to take anything but numbers).
I'm not sure what's wrong.
Code: [Select]
   sf::Font TypeKnight;
    if (!TypeKnight.LoadFromFile("Knights Templar.ttf"))
    {
        return EXIT_FAILURE;
    }
    std::string XCoord;
    std::string YCoord;
    sf::String Coord;
    Coord.SetFont(TypeKnight);
    Coord.Move(175,10);


            // Press A : Add coords
            if (myState == State0 && (Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
            {
                std::cout << "ONE" << std::endl;
                myState = State1;
            }
            if (myState == State1 && (Event.Type == sf::Event::TextEntered))
            {
                std::cout << "TWO" << std::endl;

                if (counter < 5) {
                    // Handle ASCII characters only
                    if (Event.Text.Unicode > 47 && Event.Text.Unicode < 58)
                    {
                        std::cout << "THREE" << std::endl;
                        XCoord += static_cast<int>(Event.Text.Unicode);
                        Coord.SetText(XCoord);
                    }
                    ++counter;
                }
            }
            else {
                Coord.SetText("");
            }

    App.Draw(Coord);

    App.Display();
-Wander

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Output Flashes When I Type
« Reply #1 on: August 15, 2010, 04:10:57 pm »
I don't want to discourage you, but are you actually trying to solve any of these problems yourself? Programming is all about problem solving.

Anyway, you're setting Coord to nothing ("") every frame, UNLESS you trigger the text input event. This is the problem. There's a lot of solutions. Find one.  :wink:

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Output Flashes When I Type
« Reply #2 on: August 15, 2010, 04:24:33 pm »
Quote
I don't want to discourage you, but are you actually trying to solve any of these problems yourself? Programming is all about problem solving.


All those posts I've made, I've been working on all of those problems since about noon yesterday. It is now 9:35 in the morning and I haven't slept at all. So, my answer to your question is definitely yes. :)

Some of the posts were just questions and not even code help.
-Wander

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Output Flashes When I Type
« Reply #3 on: August 15, 2010, 04:38:38 pm »
Maybe you need sleep then!  :lol:

How are you going with this problem?

If you need suggestions, I would either have a timer that clears the input after some amount of time provided there is no more text input events, or you could just leave it till the user presses return or a cancel button (surely you will be using return to confirm the input anyway?). Or both!

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Output Flashes When I Type
« Reply #4 on: August 15, 2010, 04:42:36 pm »
Maybe I do.... or some coffee... Haha.

I fixed it by taking out the thing that set it to nothing. :)
Is that not suggested?

I will be using return. I'm actually attempting to put the if statement in as we post. Trying to figure out what I'm gonna set my state to. Erm...
-Wander

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Output Flashes When I Type
« Reply #5 on: August 15, 2010, 05:29:44 pm »
Taking that part out is perfectly fine, I thought you were trying to do something else.

Good luck!

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Output Flashes When I Type
« Reply #6 on: August 15, 2010, 05:30:45 pm »
Okay cool. thanks.
-Wander

 

anything