LoginLogin

Single click on the touch screen

Root / Programming Questions / [.]

BeautySoapCreated:
I've got a turn-based game that listens for one input per turn. In a system like that, you have to suppress repeated input from a button being held down, or else it'll zoom through several turns on a single button click. BUTTON() has the nice feature that lets you specify if you're interested in just the moment when the button is down (etc.) so it's easy to get only one input at a time using, for example, BUTTON(2). No options like that are implemented for TOUCH, so to have a button-like interface on the touch screen, here's what I came up with. It works, but I'm wondering if there's a better, more typical, or more 'preferred' way. This would be at the start of each turn:
@TDOWN
TOUCH OUT TM,TX,TY
IF TM==0 GOTO @TDOWN
@TUP
TOUCH OUT TM,NotUsed,Ignored
IF TM GOTO @TUP
'(…code that branches based on X,Y data)
First it waits for the screen to be touched, and grabs the X,Y data when it is; then it waits for the touch to be lifted, but ignores that X,Y data (you can't just omit the variables, it turns out). It works, but I feel like there's a probably a standard way to handle this kind of thing, and I thought maybe those of you with more experience with this kind of interface might know what that is. Thanks!

The way I handle this is, in initialization,
TM_NEW=0
When reading the touchscreen
TM_OLD=TM_NEW
TOUCH OUT TM_NEW,TX,TY
To see if the touch has just occurred,
IF (TM_NEW && !TM_OLD)
This allows the main loop to keep looping while the stylus is held down, unlike the solution you show. It also has the bonus that if ever you want to do something for the moment the stylus is lifted from the touchscreen, you can use
IF (!TM_NEW && TM_OLD)

That's a great solution! It works not only in a turn-based environment like in my example (where one would intending to stop the loop each turn) but also fits easily into the kind of environment that lets the main loop run whether there's input or not. Thanks!

This was really helpful. If there should be a resource page on using the touch screen, this should be on it.

An alternate way of doing this is to simply check if TM_NEW==1 TM_NEW is the amount of time the touchscreen has been pressed, and it's only 1 once per touch.

An alternate way of doing this is to simply check if TM_NEW==1 TM_NEW is the amount of time the touchscreen has been pressed, and it's only 1 once per touch.
So doing it this way I wouldn't have initialize a variable to check against......right?

An alternate way of doing this is to simply check if TM_NEW==1 TM_NEW is the amount of time the touchscreen has been pressed, and it's only 1 once per touch.
So doing it this way I wouldn't have initialize a variable to check against......right?
That method will work if you are sure the condition will be tested exactly once per frame, and every frame, and yes, it removes the need for the second variable holding the 'old' value and removes the need for the initialization step of the method I described.

An alternate way of doing this is to simply check if TM_NEW==1 TM_NEW is the amount of time the touchscreen has been pressed, and it's only 1 once per touch.
So doing it this way I wouldn't have initialize a variable to check against......right?
That method will work if you are sure the condition will be tested exactly once per frame, and every frame, and yes, it removes the need for the second variable holding the 'old' value and removes the need for the initialization step of the method I described.
I guess there's more than one way to skin a cat. Thanks for the input y'all!

An alternate way of doing this is to simply check if TM_NEW==1 TM_NEW is the amount of time the touchscreen has been pressed, and it's only 1 once per touch.
Possible, but I think BeutySoap has an option to hold the stylus. In that case it wouldn't matter if you held down or not, because it would fire as soon as TM_NEW reaches 1.