Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
In TouchScript all input comes from Input Sources, i.e. objects implementing IInputSource interface. After a touch gets into the system TouchScript treats it the same as all the others no matter what input source was used.
Right now the library includes the following input sources:
- StandardInput — implements mobile touch input, desktop touch input and mouse input,
- TUIOInput — listens to an UDP socket for TUIO messages from network,
- There used to be other input sources but they all are merged into StandardInput since TouchScript 7.0.
If at the start of a game there're no input sources in the scene, an instance of StandardInput is added.
Adding a new input source
If you want to route touches from any external source or you have any other idea how to create touches, you should implement a new Input Source. This way you can be sure that all other components of TouchScript will work with your touches the same way as they work with all other input sources.
Before implementing your own input source you should check out how some other input source works. For example, StandardInput might be a good example.
If you are extending provided InputSource class you just need to call:
- addPointer(Pointer pointer) when you want to add a pointer,
- updatePointer(Pointer pointer) when the pointer needs to be updated (it was moved or its parameters changed),
- pressPointer(Pointer pointer) when the pointer touches the surface.
- releasePointer(Pointer pointer) when the pointer is released from the surface.
- removePointer(Pointer pointer) when the pointer is removed.
- cancelPointer(Pointer pointer) when the pointer is cancelled.
Every Input Source must register itself to
TouchManager.Instance using AddInput method. InputSource class does it automatically.
If an input source wants to get updates from TouchManager it must implement UpdateInput method which is called by TouchManager every frame at the beginning of update cycle in specific order.
Another method which must be implemented by an input source is CancelTouch which is called by TouchScript when a touch is cancelled internally and if this touch should be returned to the system.