0

I am testing out the feature in the SFML library mouseWheelScroll.delta but I always get a return value of 0. Why could this be?

My code that I used is below, note that on some of the first lines of code in the program I initialised the variable sf::Event event;.

    if (event.type == sf::Event::MouseWheelScrolled) {
    std::cout << "wheel movement: " << event.mouseWheelScroll.delta << std::endl;
}

Does the SFML library need a window or could it use the console? (I only ask because I am creating a console application)

  • Did you actually retrieve an actual value for your `sf::Event` instance? You can't just create an `sf::Event` object and use the members. They won't be set unless you call `sf::Window::pollEvent()` or `sf::Window::waitEvent()`. – Mario Nov 12 '17 at 18:11
  • @Mario well if I printed to the value it printed 0, so I don't think so. – Sam Fielding Nov 12 '17 at 18:15

2 Answers2

1

Thank you for the help everyone, it turns out that I had a problem with the line sf::RenderWindow v(sf::VideoMode::getDesktopMode(), "SFML"); and this was because the VC++ add-on wasn't installed, which is why I was always getting a "could not find "winmm.lib"" error.

Both of these code samples that others provided work, it was just me... sorry, but it is much appreciated!

0

I'm almost sure that you've forgotten something in your event loop. I've tried this snippet and it works fine

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

int main(){
    sf::RenderWindow v(sf::VideoMode::getDesktopMode(), "SFML");

    while (v.isOpen()){
        sf::Event event;
        while (v.pollEvent(event)){
            if (event.type == sf::Event::Closed)
                v.close();
            else if (event.type == sf::Event::MouseWheelScrolled){
                std::cout << "Wheel: " << event.mouseWheelScroll.delta << std::endl;
            }
        }
        v.clear();
        v.display();
    }
    return 0;
}

Please, try it and compare what are you doing wrong (and then share with us)

Answering your second question, i have created a render window, but i think your question it's more about if the project can be a Console Application, and in fact, this is it and if you try it, it show both console and window.

alseether
  • 1,889
  • 2
  • 24
  • 39