Hello all,
I noticed that on the examples that come with sfml 2.0 , when a key event is been coded for the following line is used:
if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
{
}
What is the significant of this part, it doesnt look like its doing anything to me since the game still runs if i remove it, so am guessing the must be a reason its there.
(event.type == sf::Event::KeyPressed)
Thanks!
I guess it's a matter of making event organization really easy and clean. For instance, you can have one function that deals with all KeyPressed events, and another function that deals with all KeyReleased events, something like this:
while (m_window->pollEvent(event))
{
switch (event.type)
{
case sf::Event::KeyPressed:
{
handleKeyPresses(event);
break;
}
case sf::Event::KeyReleased:
{
handleKeyReleases(event);
break;
}
}
}
The separation of those handlers will make your code more neat.
handleKeyPresses(sf::Event& event)
{
switch (event.key.code)
{
case sf::Keyboard::Space:
{
activateBomb;
handleKeyReleases(sf::Event& event)
{
switch (event.key.code)
{
case sf::Keyboard::Space:
{
deactivateBomb;