SFML 2.5.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Static Public Member Functions | List of all members
sf::Touch Class Reference
Window module

Give access to the real-time state of the touches. More...

`#include <Touch.hpp>`

## Static Public Member Functions

static bool | isDown (unsigned int finger)
| Check if a touch event is currently down. More...
static Vector2i | getPosition (unsigned int finger)
| Get the current position of a touch in desktop coordinates. More...
static Vector2i | getPosition (unsigned int finger, const Window &relativeTo)
| Get the current position of a touch in window coordinates. More...

## Detailed Description

Give access to the real-time state of the touches.

sf::Touch provides an interface to the state of the touches.

It only contains static functions, so it's not meant to be instantiated.

This class allows users to query the touches state at any time and directly, without having to deal with a window and its events. Compared to the TouchBegan, TouchMoved and TouchEnded events, sf::Touch can retrieve the state of the touches at any time (you don't need to store and update a boolean on your side in order to know if a touch is down), and you always get the real state of the touches, even if they happen when your window is out of focus and no event is triggered.

The getPosition function can be used to retrieve the current position of a touch. There are two versions: one that operates in global coordinates (relative to the desktop) and one that operates in window coordinates (relative to a specific window).

Touches are identified by an index (the "finger"), so that in multi-touch events, individual touches can be tracked correctly. As long as a finger touches the screen, it will keep the same index even if other fingers start or stop touching the screen in the meantime. As a consequence, active touch indices may not always be sequential (i.e. touch number 0 may be released while touch number 1 is still down).

Usage example:

if (sf::Touch::isDown(0))
{
// touch 0 is down
}
// get global position of touch 1
sf::Vector2i globalPos = sf::Touch::getPosition(1);
// get position of touch 1 relative to a window
sf::Vector2i relativePos = sf::Touch::getPosition(1, window);
sf::Touch::isDown
static bool isDown(unsigned int finger)
Check if a touch event is currently down.
sf::Touch::getPosition
static Vector2i getPosition(unsigned int finger)
Get the current position of a touch in desktop coordinates.
sf::Vector2
Utility template class for manipulating 2-dimensional vectors.
Definition: Vector2.hpp:38

See also
  sf::Joystick, sf::Keyboard, sf::Mouse

Definition at line 43 of file Touch.hpp.

## Member Function Documentation

## ◆ getPosition() [1/2]

static Vector2i sf::Touch::getPosition | ( | unsigned int | finger | ) |

static

Get the current position of a touch in desktop coordinates.

This function returns the current touch position in global (desktop) coordinates.

Parameters

  finger | Finger index

Returns
  Current position of finger, or undefined if it's not down

## ◆ getPosition() [2/2]

static Vector2i sf::Touch::getPosition | ( | unsigned int | finger,
|  | const Window & | relativeTo
| ) |  |

static

Get the current position of a touch in window coordinates.

This function returns the current touch position relative to the given window.

Parameters

  finger | Finger index
  relativeTo | Reference window

Returns
  Current position of finger, or undefined if it's not down

## ◆ isDown()

static bool sf::Touch::isDown | ( | unsigned int | finger | ) |

static

Check if a touch event is currently down.

Parameters

  finger | Finger index

Returns
  True if finger is currently touching the screen, false otherwise

The documentation for this class was generated from the following file:

- Touch.hpp