How To

How to detect if touchscreen exist

0

moechofe 2019-01-31 08:42

For my game I'd like to detect if the device own a touchscreen or a mouse because the control should be different to fit the gameplay.
Any existing solution or plan?


Timo 2019-01-31 17:34

My idea is that all NX programs should work on all platform and that the programmer shouldn't care. But I also noticed that your game works better with touchscreen. What is your idea for mouse control in your game?


was8bit 2019-02-01 03:14

It would be best to create 2 versions of the game, one for touch screen, and one for gamepad control.....


Once you have used TOUCHSCREEN, you cannot have any gamepad commands, and once you have used GAMEPAD, you cannot have any touch commands....


IF CONTROL=0 THEN
IF TOUCH THEN
END IF
ELSE
IF UP(0) THEN
END IF
END IF

Will produce an error and stop the game...


Timo 2019-02-01 08:21

I'm not a fan of separate versions. I want to find the holy grail of generic input! ;)
I could imagine different touchscreen modes, which automatically adapt to the used platform. But I'd like to know from moechofe what his idea is for his game on desktop.


was8bit 2019-02-01 10:54

I've reread the original question and perhaps the thought is that a computer mouse cannot run a program that uses TOUCHSCREEN, and a touchscreen cannot run a program that uses GAMEPAD.... if that is the actual concern, then there shouldn't be any concern because both touchscreens and computer mice can run either mode :)

A third option is KEYBOARD input, which can be used in either mode...


moechofe 2019-02-01 11:29

I think, I got it.

On LRNX, the TOUCH() only activate when then user press the mouse button.
That means a program can't never get the position of the mouse without pressing the mouse button. That my game is not easy to play on the desktop version, it force player to constantly press the mouse button to move the bat on the screen.

This is my proposal:

BEGAN event:
- with mouse: capture position when the mouse button is pressed
- with finger: capture position of the finger when it start touching the screen

MOVED event:
- with mouse: capture position of the mouse every times it's been moved
- with finger: capture position of the finger when the finger move on the screen

ENDED event:
- with mouse: capture position when the mouse button is released
- with finger: capture position of the finger when it stop touching the screen

This is the solution used by Codea (even if it's not working on desktop)
It is also the idea used by Godot with touch-emulation activated.

With that we can detect:
- move
- click/tap
- drag-on-drop
- long-press

If you want to provide a TAP() feature, I think it must be a combined detection of:
- time between the BEGAN and ENDED
- distance covered by MOVED

Like the browser did on mobile phone. There is a little delay because the detection need to wait a couple of millisecond to differentiate a tap and a long-press.

Logically, high-level gesture detection is made by the users (us). That why a combination of BEGAN-MOVED-ENDED is usefull, it allow developper to simulate everything.


moechofe 2019-02-01 11:29

@was8bit my game is not design to be played using controller but with the mouse (on desktop) and finder (on mobile)


Timo 2019-02-01 12:52

I wouldn't have to change the API for it, it simply could update TOUCH.X/Y all the time, not only when the button/finger is down.

But here is the problem: It would be possible on desktop to program things which won't work on touch screens. Like actions happening when the mouse is over something, but before the click.

My idea was to always keep everything compatible with both touchscreen and mouse:
- only single touch (multitouch doesn't work with a mouse)
- no movement without click ("hover" doesn't work with a touchscreen)

I'll have to think about it more.


was8bit 2019-02-01 15:25 (Edited)

On my windows tablet, even though it is a "microsoft" computer with a detachable keypad and touch pad to control a mouse, it is primarily a touch pad.., I almost always leave the keyboard detached and use it only as a touch screen... and even with the keypad attached with the mouse on the screen, it still lets you "touch" the screen an interact with it that way too even with the image of the mouse still on the screen.. and touching the screen to "do" something doesn't change the position of the mouse... so it's actually BOTH mouse controlled and touch controlled simultaneasly

Most people I know with "computers" today are going with these kind of tablets, not desk-top with standard mouses ... I haven't used my standard computer in at least over 5 years, so it's probably an outdated paperweight by now... i got it as an older model over 15 years ago...


moechofe 2019-02-04 22:19

@Timo: If it can help with your thought,
With the current implementation of lowresnx, it’s impossible for a program running on desktop to make something follow the mouse cursor.


Timo 2019-02-05 20:59

I'm currently thinking about something like a click lock for desktop, but I think I have to experiment a bit with it. In any case I want to avoid that you can program something on desktop which doesn't work on touchscreens.


Log in to reply.