3
\$\begingroup\$

So I’ve created a small app that is designed to be used on smartphones and tablets. Accordingly the app makes use of the sf::Touch class which determines the point on the screen of the device that the finger of the user is touching. This is required because central to the functionality of the app is that it allows the user to swipe across the screen to flick between different images. The end result should be that once a user’s finger (being pressed against the screen) has moved far enough to the left or right periphery of the screen, a swipe function is initiated and the next image moves into view. This appears in the code like so:

if (touchInput.isDown(0))
{
    sf::Vector2i currPos;
    currPos = touchInput.getPosition(0);                                                                                                        
    if (currPos.x < 540.0)                                                                      
    {
        leftSwipe(currPos);                                                                                 
    }
    else if (currPos.x > 540.0)                                                                                         
    {
        rightSwipe(currPos);                                                                                    
    }
    oldPos = currPos;                                                                                                   
}

The problem is that I am testing the application on the PC and when I click the left mouse button down (which I assumed would cause the function touchInput.isDown(0) to return true) it does not appear to update the position of touchInput and was therefore wondering if touchInput should be used on the PC at all and also if it even functions with PC inputs (like a mouse)? or whether for PC testing it would be better to use sf::Mouse instead?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

When compiling for a traditional Windows / Mac / Linux desktop setup, no this won't work. I dug through the SFML code and it turns out that the sf::Touch implementation won't really work unless you're on a touch-based device:

From https://github.com/SFML/SFML/blob/master/src/SFML/Window/Win32/InputImpl.cpp

bool InputImpl::isTouchDown(unsigned int /*finger*/)
{
    // Not applicable
    return false;
}

How you CAN test this is a bit roundabout. You'll need to compile your C++ based game for Android with the Android NDK (native development kit). From there you should be able to run the app on an Android Emulator on your computer or a push the app to a device for testing.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .