? Single click on the touch screen (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Single click on the touch screen

  • #1 ✎ 39 BeautySoap 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! Posted Edited by BeautySoap
  • #2 ✎ 477 SquareFingers 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) Posted Edited by SquareFingers
  • #3 ✎ 39 BeautySoap 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! Posted
  • #4 ✎ 97 ahavasandwich Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Pokemon Is Awesome! I love Pokemon! Express Yourself Minecraft Is Awesome! I love Minecraft! Express Yourself This was really helpful. If there should be a resource page on using the touch screen, this should be on it. Posted
  • #5 ✎ 67 Trinitro21 First Week Joined in the very first week of SmileBASIC Source Website Query Denied Hidden Easter Eggs Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength 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. Posted
  • #6 ✎ 97 ahavasandwich Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Pokemon Is Awesome! I love Pokemon! Express Yourself Minecraft Is Awesome! I love Minecraft! Express Yourself
    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?
    Posted
  • #7 ✎ 477 SquareFingers
    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.
    Posted Edited by SquareFingers
  • #8 ✎ 97 ahavasandwich Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself Pokemon Is Awesome! I love Pokemon! Express Yourself Minecraft Is Awesome! I love Minecraft! Express Yourself
    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!
    Posted
  • #9 ✎ 362 Chemicalex Drawing I like to draw! Hobbies RNG Hidden Easter Eggs Video Games I like to play video games! Hobbies
    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.
    Posted