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

Author Topic: possible keypressed event bug  (Read 4981 times)

0 Members and 1 Guest are viewing this topic.

supercatfishpro

  • Newbie
  • *
  • Posts: 5
    • View Profile
possible keypressed event bug
« on: May 21, 2015, 05:04:38 am »
not sure if this is a bug or something nasty thats just running around that i cant quite spot. but im having trouble with keypressed events. Im using these events to move around a menu that pops up when the game is paused. i know the game is pausing correctly, but its not like that matters, im pressing say the W key and its supposed to be checking for that however it totally skips over it like nothing happened.

If that were it though id know it is probably just me. however occasionally after sitting there staring at my code i go to run the game and even though i havent changed anything it says changes where made and the project needs to be rebuilt. i think thats weird, recompile and play the game and now itll work flawlessly. Of course i then proceed to (after trying to break it, or find a condition thats changing things) start staring at my code again. Upon which the cycle repeats, the program needs to be recompiled and the menu no longer works  >:(

i wont rule out me missing some bug in my code. but ive spent way too much time looking at this, and i cant find any posts online of a similar experience, so help would be appreciated.

heres my current event loop:
(the keypressed events im referring to are near the top in that first switch statement)
while (Globals::window.pollEvent(Globals::event))
                {
                        switch(event.type)
                        {
                        case sf::Event::Closed:
                                Globals::window.close();
                                break;
                        case sf::Event::KeyPressed:
                                if(event.key.code == sf::Keyboard::Tab)
                                {
                                        paused = itemMenu.toggle();
                                }
                                else if(event.key.code == sf::Keyboard::W)
                                {
                                        if(paused)
                                        {
                                        //move up in menu
                                        itemMenu.moveActiveItem(0, -1);
                                        }
                                }
                                else if(event.key.code == sf::Keyboard::S)
                                {
                                        if(paused)
                                        {
                                        //move down in menu
                                        itemMenu.moveActiveItem(0, 1);
                                        }
                                }
                                else if(event.key.code == sf::Keyboard::A)
                                {
                                        if(paused)
                                        {
                                        //move left menu
                                        itemMenu.moveActiveItem(-1, 0);
                                        }
                                }
                                else if(event.key.code == sf::Keyboard::D)
                                {
                                        if(paused)
                                        {
                                        //move right menu
                                        itemMenu.moveActiveItem(1, 0);
                                        }
                                }
                                else if(event.key.code == sf::Keyboard::E)
                                {
                                        if(!paused)
                                        {
                                                //this is gonna need some work. currently does nothing
                                                player.attack();

                                        }
                                        else
                                        {
                                                //select item inside the ui object?
                                        }
                                }
                                break;
                        default:
                                break;
                        }
                }

                if(!paused) //check for movement keys pressed
                {
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
                        {
                                if(!(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S)))
                                {
                                                //move up
                                                player.moveEvent(0, 1);
                                                Globals::cameraPosition = Globals::window.getPosition();
                                }
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                        {
                                        //move down
                                        player.moveEvent(0, -1);
                                        Globals::cameraPosition = Globals::window.getPosition();
                        }
       
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
                        {
                                if(!(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D)))
                                {
                                                //move left
                                                player.moveEvent(-1, 0);
                                                Globals::cameraPosition = Globals::window.getPosition();
                                }
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D))
                        {
                                        //move right
                                        player.moveEvent(1, 0);
                                        Globals::cameraPosition = Globals::window.getPosition();
                        }
                }

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: possible keypressed event bug
« Reply #1 on: May 21, 2015, 08:45:14 am »
You are pulling events inside Globals::event and then testing event instead.

supercatfishpro

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: possible keypressed event bug
« Reply #2 on: May 21, 2015, 09:25:49 am »
You are pulling events inside Globals::event and then testing event instead.

Sorry about that. That was a side affect of me tinkering to try and find the problem all of them are normally the Globals::event.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: possible keypressed event bug
« Reply #3 on: May 21, 2015, 09:57:37 am »
If you don't initialize paused it's undefined whether it will be trur or false.
Also if you have a global window, you have a bad design and possibility of certain things going wrong. I advise you to not use global variables at all.

Other than that, the code is incomplete and we can't tell you much more. Provide a minimal and compilable example instead.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

supercatfishpro

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: possible keypressed event bug
« Reply #4 on: May 21, 2015, 10:27:19 am »
If you don't initialize paused it's undefined whether it will be trur or false.
Also if you have a global window, you have a bad design and possibility of certain things going wrong. I advise you to not use global variables at all.

Other than that, the code is incomplete and we can't tell you much more. Provide a minimal and compilable example instead.
sorry, i think id better post the rest of the code. Dont worry everything isnt global, its the name of the class those are in
(i know my code design isnt perfect, but thats more of why im building this, to learn :D )

heres globals.h
//Evan

#ifndef GLOBALS_H
#define GLOBALS_H

#include <vector>
#include <string>
#include <stdexcept>
#include <iostream>
#include <memory>


#include "Map.h"
#include "Button.h"
#include "PlayerCharacter.h"
#include "UIPlayerMenu.h"
#include "MagicWrench.h"

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

struct TextureArray
{
        std::string fileName;
        sf::Texture texture;
};

class Globals
{
private:       
        bool paused;

        static sf::RenderWindow window;
        static sf::Event event;
        static sf::View view;
        static sf::View userInterface;
        static sf::Font gameFont;
        static sf::Clock gameClock;
        static sf::Time gameTime;
        static sf::Time accumulator;

        static UIPlayerMenu itemMenu;

        TextureArray textures[5];
        Map gameMap;
         //temp fix - 1 is for game 2 is for mapMaker
        int gameMode;

        PlayerCharacter player;
        //ai for enemies
        //assume this is a survival game,
        //if it is then ai's arent particularly targeting you over another ai
        //lets assume they have multiple methods of killing an enemy, for example
        //fist, foot, or staff
        //if ai gets kill with staff then that skill levels up and that specific ai becomes better,
        //this state is also possibly saved if the player is killed
        //what this would cause is a more dynamic world that seemed more alive
        //this could also initialize the neural network programming technique i want to implement

public:
        Globals();
        Globals(int mapx, int mapy, int cameraX, int cameraY);

        void mainMenu();
        void initializeGame();
        void runGame();
        void handleEvents();
        void update();
        void runMapMaker();

        sf::Texture getTexture(int textureNumb);
               
};

#endif

 

and heres Globals.cpp
//Evan

#include "globals.h"

Globals::Globals()
{
        Globals::textures[0].fileName = "overWorld.png";
        Globals::textures[1].fileName = "menuButton.png";
        Globals::textures[2].fileName = "menuButtonPressed.png";
        Globals::textures[3].fileName = "king.png";
        Globals::textures[4].fileName = "titleScreen.png";
        gameMode = 0;
        accumulator = sf::Time::Zero;
        paused = false;
}

Globals::Globals(int mapx,int mapy, int cameraX, int cameraY)
{
        Globals::textures[0].fileName = "overWorld.png";
        Globals::textures[1].fileName = "menuButton.png";
        Globals::textures[2].fileName = "menuButtonPressed.png";
        Globals::textures[3].fileName = "king.png";
        Globals::textures[4].fileName = "titleScreen.png";
        gameMode = 0;
        accumulator = sf::Time::Zero;

        paused = false;
}

void Globals::initializeGame()
{
        //window and view setup
        Globals::window.create(sf::VideoMode(1280, 640), "Kill It With Fire!");
        Globals::window.setKeyRepeatEnabled(false);
        Globals::window.setFramerateLimit(60);
        Globals::view = sf::View(sf::FloatRect(0, 0, 1280, 640));
        Globals::userInterface = sf::View(sf::FloatRect(0, 0, 1280, 640));
        Globals::window.setView(view);
        Globals::view.setCenter(640, 320);

        //font setup
        if(!gameFont.loadFromFile("kongtext.ttf"))
        {
                throw(42);
        }

        //tiles setup
        for(int i = 0; i < 5; i++)
        {
                if(!Globals::textures[i].texture.loadFromFile(Globals::textures[i].fileName))
                {
                        throw(42);
                }
        }

        //insert main menu screen here
        mainMenu();

        //create character
        player = PlayerCharacter(textures[3].texture);
        player.setSpritePostion(sf::Vector2f(640, 320));

        if(Globals::window.isOpen())
        {
                //map loading
                gameMap = Map(100, 100);
                gameMap.setDefaultTiles(textures[0].texture);
                for(int i = 0; i < 40; i++)
                {
                        for(int j = 0; j < 20; j++)
                        {
                                if(gameMap.validTilePosition(i, j))
                                {
                                        gameMap.setTileDefaultPosition(i, j, i*32, j*32);
                                }
                        }
                }

                Globals::window.setMouseCursorVisible(false);

                if(gameMode == 1)
                {
                        runGame();
                }
                else
                {
                        runMapMaker();
                }      
        }
}


void Globals::runMapMaker()
{
        sf::Texture menuTexture;
        if(!menuTexture.loadFromFile("mapMakerMenu.png"))
        {
                throw(42);
        }
        itemMenu = UIPlayerMenu(true, menuTexture, textures[0].texture);
        itemMenu.setPosition(1132.0, 0.0);
        itemMenu.toggle();//why?

        std::shared_ptr<Weapon> newWeapon(new MagicWrench(textures[0].texture));
        player.setWeapon(newWeapon); //put derived class magicWrench into char inventory

        //game loop
        while (Globals::window.isOpen())
        {
                gameTime = gameClock.restart();

                handleEvents();

                if(!paused)
                {
                        update();
                }
               
                Globals::window.clear();
                Globals::window.setView(Globals::view);
                Globals::gameMap.draw(window);
                Globals::window.setView(Globals::userInterface);
                Globals::player.draw(window);
                if(itemMenu.getCanDraw())
                {
                        itemMenu.draw(window);  //change item menu to a uiplayermenu when its finished
                }
                Globals::window.display();
        }
}

void Globals::runGame()
{
        //game loop
        while (Globals::window.isOpen())
        {
                while (Globals::window.pollEvent(Globals::event))
                {
                        switch(Globals::event.type)
                        {
                        case sf::Event::Closed:
                                Globals::window.close();
                                break;
                        default:
                                break;
                        }
                }


                //check for movement keys pressed
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
                {
                        if(!(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S)))
                        {
                                //move up
                                Globals::view.move(0.0, -5.0);
                                //change to player.move
                        }
                }
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                {
                        //move down
                        Globals::view.move(0.0, 5.0);
                        //change to player.move
                }

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
                {
                        if(!(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D)))
                        {
                                //move left
                                Globals::view.move(-5.0, 0.0);
                                //change to player.move
                        }
                }
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D))
                {
                        //right
                        Globals::view.move(5.0, 0.0);
                        //change to player.move
                }
                Globals::window.clear();
                Globals::window.setView(Globals::view);
                Globals::gameMap.draw(window);
                Globals::window.display();
                Globals::gameClock.restart();
        }
}

void Globals::mainMenu()
{
        Button mapMaker(&textures[1].texture, &textures[2].texture, std::string("Map Maker"), sf::Vector2f(100.0f, 580.0f), &gameFont);
        Button playGame(&textures[1].texture, &textures[2].texture, std::string("Play!"), sf::Vector2f(350.0f, 580.0f), &gameFont);
        sf::Sprite mainMenuImage(textures[4].texture);
        sf::Vector2i localPosition;
        bool clicked = false;
        bool countDown = false;
        sf::Time timer = sf::Time::Zero;
        while(timer <= sf::seconds(0.5))
        {
                if(countDown)
                {
                        timer += sf::seconds(1.0/60.0);
                }
                while (Globals::window.pollEvent(Globals::event))
                {
                        if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && countDown == 0)
                        {
                                // left mouse button is pressed check if button is clicked
                                localPosition = sf::Mouse::getPosition(Globals::window);
                                clicked = mapMaker.checkIfClick(&sf::Vector2f(localPosition.x, localPosition.y));
                                if(clicked)
                                {
                                        gameMode = 2;
                                        countDown = true;
                                }
                                else
                                {
                                        clicked = playGame.checkIfClick(&sf::Vector2f(localPosition.x, localPosition.y));
                                        if(clicked)
                                        {
                                                gameMode = 1;
                                                countDown = true;
                                        }
                                }
                        }
                }

                Globals::window.clear();
                Globals::window.draw(mainMenuImage);
                Globals::window.draw(*mapMaker.getSprite());
                Globals::window.draw(*mapMaker.getText());
                Globals::window.draw(*playGame.getSprite());
                Globals::window.draw(*playGame.getText());
                Globals::window.display();
        }
}

void Globals::handleEvents()
{
                while (Globals::window.pollEvent(Globals::event))
                {
                        switch(event.type)
                        {
                        case sf::Event::Closed:
                                Globals::window.close();
                                break;
                        case sf::Event::KeyPressed:
                                if(Globals::event.key.code == sf::Keyboard::Tab)
                                {
                                        paused = itemMenu.toggle();
                                }
                                else if(Globals::event.key.code == sf::Keyboard::W)
                                {
                                        if(paused)
                                        {
                                        //move up in menu
                                        itemMenu.moveActiveItem(0, -1);
                                        }
                                }
                                else if(Globals::event.key.code == sf::Keyboard::S)
                                {
                                        if(paused)
                                        {
                                        //move down in menu
                                        itemMenu.moveActiveItem(0, 1);
                                        }
                                }
                                else if(Globals::event.key.code == sf::Keyboard::A)
                                {
                                        if(paused)
                                        {
                                        //move left menu
                                        itemMenu.moveActiveItem(-1, 0);
                                        }
                                }
                                else if(Globals::event.key.code == sf::Keyboard::D)
                                {
                                        if(paused)
                                        {
                                        //move right menu
                                        itemMenu.moveActiveItem(1, 0);
                                        }
                                }
                                else if(Globals::event.key.code == sf::Keyboard::E)
                                {
                                        if(!paused)
                                        {
                                                //this is gonna need some work. currently does nothing
                                                player.attack();
                                                sf::Vector2i playerPosition = player.getLocation();
                                                gameMap.setTile(playerPosition.x / 32, playerPosition.y / 32, player.summon()); // divided by length of a tile
                                        }
                                        else
                                        {
                                                //select item inside the ui object?
                                                //this will allow you to set the current type of tile to be placed as well as its properties (colidable, animated, etc)
                                        }
                                }
                                break;
                        default:
                                break;
                        }
                }

                if(!paused) //check for movement keys pressed
                {
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
                        {
                                if(!(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S)))
                                {
                                                //move up
                                                player.moveEvent(0, 1, Globals::window.getPosition());
                                }
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S))
                        {
                                        //move down
                                        player.moveEvent(0, -1, Globals::window.getPosition());
                        }
       
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
                        {
                                if(!(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D)))
                                {
                                                //move left
                                                player.moveEvent(-1, 0, Globals::window.getPosition());
                                }
                        }
                        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D))
                        {
                                        //move right
                                        player.moveEvent(1, 0, Globals::window.getPosition());
                        }
                }
}

void Globals::update()
{
        //all of the code for everything that needs to be upadted in the game is to be put here
        //update player information
        player.update(view, gameClock.getElapsedTime() + fps);
}

sf::Texture Globals::getTexture(int textureNumb)
{
        if(textureNumb < sizeof(textures))
                {
                return textures[textureNumb].texture;
                }
        else
                {
                std::cout<<"error getting texture number: "<< textureNumb << " using texture 1 instead.";
                return textures[0].texture;
                }
}

//static globals variables
sf::RenderWindow Globals::window;
sf::Event Globals::event;
sf::View Globals::view;
sf::View Globals::userInterface;
sf::Font Globals::gameFont;
sf::Clock Globals::gameClock;
sf::Time Globals::gameTime;
sf::Time Globals::accumulator;
UIPlayerMenu Globals::itemMenu;

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: AW: possible keypressed event bug
« Reply #5 on: May 21, 2015, 11:26:59 am »
Let me quote myself again and make the important part stand out a bit more:
Provide a minimal and compilable example instead.

I don't have the time to crawl through the whole source code where 80% is not needed to reproduce the issue. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

supercatfishpro

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: possible keypressed event bug
« Reply #6 on: May 21, 2015, 11:50:02 am »
Let me quote myself again and make the important part stand out a bit more:
Provide a minimal and compilable example instead.

I don't have the time to crawl through the whole source code where 80% is not needed to reproduce the issue. ;)

wow, thats totally my bad, sorry about that. heres some example code i cooked up, pretty sure i included everything that should be in it, thanks for any help :)

class Globals
{
private:
        bool toggle;
        sf::RenderWindow window;

public:
void rungame()
        {
        Globals::window.create(sf::VideoMode(1280, 640), "game");
       
        Globals::window.setKeyRepeatEnabled(false);
       
        Globals::window.setFramerateLimit(60);

        while (Globals::window.isOpen())
        {
        while (Globals::window.pollEvent(Globals::event))
                {
                            switch(event.type)
                            {
                            case sf::Event::Closed:
                                Globals::window.close();
                                break;
                            case sf::Event::KeyPressed:
                                if(event.key.code == sf::Keyboard::Tab)
                                 {
                                     paused = true;
                                 }
                                else if(event.key.code == sf::Keyboard::W) // my problem is here no matter        
                               //what this, and statements like this are getting ignored
                                {
                                    if(paused)
                                    {
                                    //do something
                                    }
                                }
                                break;
                            }
                 }
        //update things
        //draw things
        }
}
}

int main()
{
Globals game;
game.rungame();
}
« Last Edit: May 21, 2015, 11:54:36 am by supercatfishpro »

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: possible keypressed event bug
« Reply #7 on: May 21, 2015, 11:54:25 am »
LOL. Whatever you need.
Main conception. Else I have class of bool key status based on events.
Else read events to your own key class only at begin of frame.
And else - secret event at Windows OS )) -- if you detect any Shift release no Shifts at this time pressed !))

RenderWindow wIn;
Event eV;
while(wIn.pollEvent(eV))
{
        if(eV.type == Event::KeyPressed)
        {
                switch (eV.key.code)
                {
                        case (Keyboard::..)
                        {
                                // do what you need
                                break;
                        }
                        case (Keyboard::..)
                        {
                                // do what you need
                                break;
                        }
                        default : break;
                }
        }
        else if(eV.type == Event::KeyReleased)
        {
                // same as above
        }
}
« Last Edit: May 21, 2015, 12:00:26 pm by Redee »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: possible keypressed event bug
« Reply #8 on: May 21, 2015, 12:07:22 pm »
Sorry Redee but I'm not sure how many will understand what you were trying to say, because I sure don't understand you. :-[

Anyways, here is an actual minimal, complete and compilable example and I've even included debugging information. This works flawlessly for me:

#include <SFML/Graphics.hpp>
#include <iostream>

class Globals
{
private:
    bool toggle;
    sf::RenderWindow window;

public:
    void rungame()
    {
        window.create(sf::VideoMode(1280, 640), "game");

        window.setKeyRepeatEnabled(false);
        window.setFramerateLimit(60);

        bool paused = false;

        while(window.isOpen())
        {
            sf::Event event;
            while(window.pollEvent(event))
            {
                switch(event.type)
                {
                case sf::Event::Closed:
                   window.close();
                   break;
                case sf::Event::KeyPressed:
                    std::cout << "Key pressed" << std::endl;

                    if(event.key.code == sf::Keyboard::Tab)
                    {
                        paused = true;
                        std::cout << "Game paused" << std::endl;
                    }
                    else if(event.key.code == sf::Keyboard::W) // my problem is here no matter
                        //what this, and statements like this are getting ignored
                    {
                        std::cout << "W pressed" << std::endl;
                        if(paused)
                        {
                            ++count;
                            std::cout << "Do something " << std::endl;
                            //do something
                        }
                    }
                    break;
                }
            }

            window.clear();
            window.display();
        }
    }
};

int main()
{
    Globals game;
    game.rungame();
}

Btw. you should not use Globals:: to access (non-static) member variables!
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

supercatfishpro

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: possible keypressed event bug
« Reply #9 on: May 21, 2015, 12:23:52 pm »
Sorry Redee but I'm not sure how many will understand what you were trying to say, because I sure don't understand you. :-[

Anyways, here is an actual minimal, complete and compilable example and I've even included debugging information. This works flawlessly for me:

<code>

Btw. you should not use Globals:: to access (non-static) member variables!

thanks for the tips, however my problem is still here. the event handling code is identical to my current code, only (of course simplified) however sometimes when i try to run it, say in the debugger, its just skipping over the
 else if(event.key.code == sf::Keyboard::W)
sometimes itll work sometimes it wont, but theres no code that i can find, or should exist thats restricting if from going into that if statement :/
« Last Edit: May 21, 2015, 11:00:52 pm by eXpl0it3r »

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: possible keypressed event bug
« Reply #10 on: May 21, 2015, 12:53:03 pm »
What skipping about you saying.
No skip in this part of code >>
while(wIn.pollEvent(eV))
{}

And key event always store ONE key at eV.key.code.
Else - events accumulate all time and will stay to queue.
« Last Edit: May 21, 2015, 12:55:34 pm by Redee »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: possible keypressed event bug
« Reply #11 on: May 21, 2015, 09:15:35 pm »
Supercatfishpro, the code that you posted works. At least, after the adjustments to make it compile. i.e.:
#include <SFML/graphics.hpp>
at the top, and
        sf::Event event;
        bool paused = false;
declared in the private section.

(click to show/hide)

It would be up to you to insert things for it to do when W is pressed (etc.).

However, eXpl0it3r posted an example of a much better and cleaner way to write the same thing with responses to actions and window updating. Does that example work for you?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything