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

Author Topic: Events Misfiring?  (Read 2246 times)

0 Members and 1 Guest are viewing this topic.

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Events Misfiring?
« on: September 02, 2010, 04:35:55 am »
so here's the spiel,

In my Game i have a function that acts like a regular game loop to play a cutscene video, In it i read in events to know if the user has pressed the escape key, if so, i exit out of the cutscene and begin the real game loop. however, while watching the movie, sometimes it will randomly exit, and go to the normal game loop, i put a cout, in the Event when its suppose to be fired, and sure enough, when it exits randomly, the cout' is printed.

which is weird because my hand is nowhere near the Escape key.
Is this a known issue or am i doing something stupid?

the codez

Code: [Select]


//Play fullscreened Cutscene
bool MoviePlayer::playCutscene(sf::RenderWindow *rendow, MovieClip *cutscene, bool player_control, sf::Key::Code escKey)
{
if(!cutscene->isValid() )
{
return false;
}

bool run_cutscene = true;

cutscene->Loop(false);
cutscene->SetOrigin(0,0);
cutscene->SetPosition(0, 0);





while (run_cutscene)
     {
// Process events
         sf::Event Event;
         while (rendow->GetEvent(Event))
         {
//Exit if the close button is pressed
 if (Event.Type == sf::Event::Closed)
{
                 rendow->Close();
run_cutscene = false;
}
 
           //The Problem! this gets called randomly sometimes
if(Event.Key.Code == escKey)
{
              cout << "Escaped Cutscene!\n";
run_cutscene = false;

}

}//End of Events

cutscene->Resize(rendow->GetWidth(), rendow->GetHeight());
//Update images and sound
cutscene->Update( rendow->GetFrameTime() );


 //if finsished, exit cutscene
if(cutscene->isFinished())
{
run_cutscene = false;
}

//Draw the cutscenes
rendow->Clear();
cutscene->Draw(rendow);
rendow->Display();
}//End ov While loop

return cutscene->isFinished();
}//EoF


any ideas?

also, the problem is also in the main game loop, I've known about this problem for a while, but have finally decided to deal with it now so my cutscene system is finalized
John Carmack can Divide by zer0.

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Events Misfiring?
« Reply #1 on: September 02, 2010, 04:57:01 am »
I don't know if this is it, but I think Event.Key.Code doesn't make sense if the event was NOT of type KeyPressed.

So instead of
Code: [Select]

//The Problem! this gets called randomly sometimes
          if(Event.Key.Code == escKey)
          {
              cout << "Escaped Cutscene!\n";
             run_cutscene = false;

          }


you should write

Code: [Select]

//The Problem! this gets called randomly sometimes
          if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == escKey)
          {
              cout << "Escaped Cutscene!\n";
             run_cutscene = false;

          }


Let me know if that solves it.

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Events Misfiring?
« Reply #2 on: September 02, 2010, 05:11:44 am »
wow, I was doing something stupid, Thank you!
seems to work fine now
John Carmack can Divide by zer0.