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

Author Topic: Input Is not being handled well  (Read 3460 times)

0 Members and 1 Guest are viewing this topic.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Input Is not being handled well
« on: December 10, 2010, 04:11:55 am »
Well I have built my program fine but when I try and use it and I use my mouse on the window it stops working. I am pretty sure it is not handling input correctly... Also one of my images is just showing up white. It is just an inherited sprite class...

Terrydil

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Input Is not being handled well
« Reply #1 on: December 10, 2010, 04:42:08 am »
If the program locks up when processing events there might be some sort of never ending while() loop in your event handling functions.  A white sprite could be the result of problems loading/setting the image or the way its being drawn.  Obviously its hard to know what could be causing either problem without seeing how you're trying to do it so try recreating the problems with a minimal (but complete, so people can test it) example.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Input Is not being handled well
« Reply #2 on: December 10, 2010, 04:55:44 am »
Quote from: "Terrydil"
If the program locks up when processing events there might be some sort of never ending while() loop in your event handling functions.  A white sprite could be the result of problems loading/setting the image or the way its being drawn.  Obviously its hard to know what could be causing either problem without seeing how you're trying to do it so try recreating the problems with a minimal (but complete, so people can test it) example.


Well Here is my code...

Code: [Select]
sf::Event Event1;

while(App.GetEvent(Event1))
{
if(Event1.Closed == sf::Event::Closed)
{
App.Close();
}

if ( (Event1.KeyPressed == sf::Key::Up) && (App.GetInput().IsKeyDown(sf::Key::Up)))
{
Player1.Move(0,1);
}
if ( (Event1.KeyPressed == sf::Key::Down) && (App.GetInput().IsKeyDown(sf::Key::Down)))
{
Player1.Move(0,-1);
}
if ( (Event1.KeyPressed == sf::Key::Right) && (App.GetInput().IsKeyDown(sf::Key::Right)))
{
Player1.Move(1,0);
}
if ( (Event1.KeyPressed == sf::Key::Left) && (App.GetInput().IsKeyDown(sf::Key::Left)))
{
Player1.Move(-1,0);
}

else
{
Player1.Move(1,0);
}
}

Terrydil

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Input Is not being handled well
« Reply #3 on: December 10, 2010, 02:18:22 pm »
And what exactly happens when "it stops working"?  The program crashes with an error?  Turns black? etc.

Also, thats not a complete example.  In other words, I can't take the code you posted, run it, and recreate your problem.  See if you can make as small of an example as you can that actually runs and reproduces your problem.  This can also be a good way to try and debug on your own because it forces you to find the specific part of your program that is causing problems and makes it more obvious what is going wrong.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Input Is not being handled well
« Reply #4 on: December 11, 2010, 12:08:36 am »
Quote from: "Terrydil"
And what exactly happens when "it stops working"?  The program crashes with an error?  Turns black? etc.

Also, thats not a complete example.  In other words, I can't take the code you posted, run it, and recreate your problem.  See if you can make as small of an example as you can that actually runs and reproduces your problem.  This can also be a good way to try and debug on your own because it forces you to find the specific part of your program that is causing problems and makes it more obvious what is going wrong.


The program just crashes.. Also you don't need the full example (10 files) since something is only wrong with the input...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Input Is not being handled well
« Reply #5 on: December 11, 2010, 12:05:08 pm »
Quote
Also you don't need the full example (10 files) since something is only wrong with the input...

But the piece of code that you show is perfectly fine, if we take it and put it in an empty project it won't crash. That's why we need you to extract from your project the minimal amount of code that can be tested (= complete) and that reproduces the problem.
Laurent Gomila - SFML developer

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Input Is not being handled well
« Reply #6 on: December 11, 2010, 04:25:23 pm »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Input Is not being handled well
« Reply #7 on: December 11, 2010, 05:05:49 pm »
We don't want your entire project, with 99% of code not relevant to the problem. We want something minimal that focuses on the problem and that we can test quickly.
Laurent Gomila - SFML developer

Terrydil

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Input Is not being handled well
« Reply #8 on: December 11, 2010, 05:10:45 pm »
Does your program crash with an error or just close successfully?  Wouldn't

Code: [Select]
if (Event1.Closed == sf::Event::Closed)

always be true, in which case App.Close() gets called right away?  I'm still pretty drunk so I can't tell if that makes sense or not  :roll:

//edit: typo

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Input Is not being handled well
« Reply #9 on: December 11, 2010, 05:14:59 pm »
Quote from: "Terrydil"
Does your program crash with an error or just close successfully?  Wouldn't

Code: [Select]
if (Event1.Closed == sf::Event::Closed)

always be true, in which case App.Close() gets called right away?  I'm still pretty drunk so I can't tell if that makes sense or not  :roll:

//edit: typo


Thanks! I knew you only needed my first post!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Input Is not being handled well
« Reply #10 on: December 11, 2010, 05:15:05 pm »
Quote
I'm still pretty drunk so I can't tell if that makes sense or not

It does :lol:

The correct code is
Code: [Select]
if(Event1.Type == sf::Event::Closed)
{
    App.Close();
}

same for all other events.
Laurent Gomila - SFML developer

 

anything