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

Pages: [1]
1
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.

2
Window / 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 ?
         
   


         

Pages: [1]