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

Author Topic: Events - Events outside "while (window.pollEvent(event))"  (Read 2222 times)

0 Members and 1 Guest are viewing this topic.

Lagermeister

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Events - Events outside "while (window.pollEvent(event))"
« on: July 30, 2022, 09:11:50 pm »
I am following a tutorial. The author has choosen a structure for handling keyboards inputs which i do not really understand.

This is the section for keyboard input.

A. Loop

while (window.pollEvent(event))
e.g. if (event.key.code == Keyboard::Return && state == State::PLAYING) state = State::PAUSED;


B. Realtime input

e.g. if (Keyboard::isKeyPressed(Keyboard::W)) player.moveUp();

C. Special Game State input

e.g. if (event.key.code = Keyboard::Num1) state = State::PLAYING; // No loop

I struggle to understand part C. Every time a key is pressed, event is created and added to a queue. Part A loops through the queue and removes any event. So which event is used by part C ? It is already in a new queue and what happens when there are several new events already in the queue ? Does event.key.code always point to the next event which should leave the queue ?

Thanks for help ?
         
   


         

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Events - Events outside "while (window.pollEvent(event))"
« Reply #1 on: July 30, 2022, 09:44:31 pm »
Which tutorial is this?
event really shouldn't be used outside of the event loop, that would miss events if more than one arrives in a frame.

Lagermeister

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Events - Events outside "while (window.pollEvent(event))"
« Reply #2 on: July 30, 2022, 11:01:23 pm »
The book is "Begin C++ Programming" , page 227

As part C has much more code lines so it was design decision but then he should have sent code to new functions.