dsfml.window.touch

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, 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).

Members

Classes

Touch
class Touch

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

Examples

1 if (Touch.isDown(0))
2 {
3    // touch 0 is down
4 }
5 
6 // get global position of touch 1
7 Vector2i globalPos = Touch.getPosition(1);
8 
9 // get position of touch 1 relative to a window
10 Vector2i relativePos = Touch.getPosition(1, window);

See Also

$(JOYSTICK_LINK), $(KEYBOARD_LINK), $(MOUSE_LINK)

Meta