While you should avoid relying on it (it is better to just write code that makes sense for both touch and mouse), sometimes you may want to do something special for touch devices. For example, you may want to display buttons to do some actions on touch devices, where on desktops the same action can be performed by a keyboard shortcut. For example, a button to "Exit Game" on touch devices, where on desktops you can just press Escape
key. Like this:
uses CastleApplicationProperties;
procedure TViewMain.Start;
begin
inherited;
ButtonExitGame.Exists := ApplicationProperties.TouchDevice;
end;
To test how such code behaves on desktop, you can (all the methods below do the same thing):
-
Run the application using editor selecting first "Run → Run Parameters → Pretend Touch Device" from the editor menu.
-
Run the application from command-line adding the --pretend-touch-device
option.
-
Or just manually set ApplicationProperties.TouchDevice
property to true
.
For example, this allows to test how does the "Exit Game" button, mentioned above as an example, looks and works on a desktop.
Note
|
Some devices with touch screen, like Android and Nintendo Switch, allow to plug external keyboard and mouse. We don’t support it now in any special way, but we may in the future, and then user will be able to use normal mouse behavior in your mobile game. It also means that inferring too much from ApplicationProperties.TouchDevice being true isn’t wise — the device may have a touch screen, but user may be using external keyboard / mouse.
|