? How do I use the touch screen/bottom screen? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
This website has been moved, please see this post

How do I use the touch screen/bottom screen?

  • #1 ✎ 322 RNGesus Touch Screen/Bottom Screen Tutorial Hello everyone, I have decided to make a tutorial about using the bottom screen. Let's start. First copy all of this code into SmileBASIC: ACLS:BGMSTOP:XSCREEN 2:SYSBEEP=0:OPTION STRICT @TCHSCRNSET DISPLAY 1 SPSET 0,0,0,0,0 VAR TM VAR TX VAR TY DISPLAY 0 @LOOP GOSUB @TCHSCRN VSYNC 1 GOTO @LOOP @TCHSCRN DISPLAY 1 TOUCH OUT TM,TX,TY SPOFS 0,TX,TY IF TM<=0 THEN SPOFS 0,-1,-1 DISPLAY 0 RETURN What this does is set up a 1*1 sprite on the bottom screen and moves it to where you are touching the bottom screen. And if you aren't touching the bottom screen, then the sprite is moved off of the screen. The 1*1 sprite is invisible, so you can't see it. You can use this by using SPHIT or SPHITSP. Let's break it down ACLS:BGMSTOP:XSCREEN 2:SYSBEEP=0:OPTION STRICT What this does is clear the screen, stops all music, turns off the keyboard, turns of system noises, and makes variables have to be set using VAR. @TCHSCRNSET DISPLAY 1 SPSET 0,0,0,0,0 VAR TM VAR TX VAR TY DISPLAY 0 What this part does is that it makes a place in the code called @TCHSCRNSET. Then it tells SmileBASIC to use the bottom screen for all of the following commands. And then it sets up a 1*1 invisible sprite on the bottom screen. Then it sets the variables TM, TX, and TY as 0. Then it tells SmileBASIC to use the top screen for all of the following commands. @LOOP GOSUB @TCHSCRN VSYNC 1 GOTO @LOOP What this does is that is makes a place in the code called @LOOP. Then it tells SmileBASIC to go to the place called @TCHSCRN and return to the the this command once the command RETURN is given. VSYNC 1 tells SmileBASIC to wait 1/60 of a second. Then it tells SmileBasic to goto the place called @LOOP but won't return if the command RETURN is given. @TCHSCRN DISPLAY 1 TOUCH OUT TM,TX,TY SPOFS 0,TX,TY IF TM<=0 THEN SPOFS 0,-1,-1 DISPLAY 0 RETURN What this does is that it makes a place in the code called @TCHSCRN. Then it tells SmileBASIC to use the bottom screen for all of the following commands. Then it makes TM equal the amount of time the screen is touch, TX equal the x-coordinate of where the screen is touched, and TY equal the y-coordinate of where the screen is touched. Then is moves the 1*1 sprite at the coordinates of where the screen is touched. Then it tells SmileBASIC if the screen isn't being touched then put the 1*1 sprite off of the screen. Then it tells SmileBASIC to use the top screen for all of the following commands. Then it tells SmileBASIC to go back to where the GOSUB command was used. I hope this tutorial was helpful! There is also a shorter way which does the same thing. @TCHSCRN DISPLAY 1 VAR TM VAR TX VAR TY IF TM==0 AND TX==0 AND TY==0 THEN SPSET 0,0,0,1,1 TOUCH OUT TM,TX,TY IF TM==0 THEN TX=-1:TY=-1 SPOFS 0,TX,TY DISPLAY 0 RETURN Posted Edited by RNGesus
  • #2 ✎ 124 kldck_hul First Month Joined in the very first month of SmileBASIC Source Website Scholar Received for knowing a great deal about programming topics Achievements Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself You don't HAVE TO use a sprite for the touchscreen. It does look nice and is probably how you want to do it, but you can also use SPHITRC. SPHITRC( BUTTON_ID, TX-5, TY-5, 10, 10 ) Will check if the user is touching a button with a 5 pixel snapping range. Posted Edited by kldck_hul
  • #3 ✎ 322 RNGesus Yes, but that is harder to deal with AND it's not as exact. Posted
  • #4 ✎ 124 kldck_hul First Month Joined in the very first month of SmileBASIC Source Website Scholar Received for knowing a great deal about programming topics Achievements Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself How so? It's in the same coordinate system. You pass all the same arguments to your invisible sprite DEF. This consolidates those commands in a sense. The math behind the scenes is the exact same. You can change the size of your box to make it snap more or less as well. Posted Edited by kldck_hul
  • #5 ✎ 270 NeatNit First Week Joined in the very first week of SmileBASIC Source Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself While I generally agree with kldck_hul, there is still one advantage to using a sprite - if you have 50 buttons, you'd only need to use one command and you will know which button was hit. If you use SPHITRC, you'd have to do it for each button separately. Posted
  • #6 ✎ 124 kldck_hul First Month Joined in the very first month of SmileBASIC Source Website Scholar Received for knowing a great deal about programming topics Achievements Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself @NeatNit Very good point. I've been doing a lot of non-sprite buttons, and that FOR loop has been easiest to implement there; this was not something I was thinking about. Posted Edited by kldck_hul
  • #7 ✎ 72 calc84maniac OSP Contest 1 Winner I won the first SmileBASIC Source OSP Contest! Programming Contest Amazing Page Hidden Achievements Scholar Received for knowing a great deal about programming topics Achievements
    While I generally agree with kldck_hul, there is still one advantage to using a sprite - if you have 50 buttons, you'd only need to use one command and you will know which button was hit. If you use SPHITRC, you'd have to do it for each button separately.
    Not true, SPHITRC allows specifying a range of sprites, and/or a collision mask.
    Posted
  • #8 ✎ 270 NeatNit First Week Joined in the very first week of SmileBASIC Source Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself
    While I generally agree with kldck_hul, there is still one advantage to using a sprite - if you have 50 buttons, you'd only need to use one command and you will know which button was hit. If you use SPHITRC, you'd have to do it for each button separately.
    Not true, SPHITRC allows specifying a range of sprites, and/or a collision mask.
    Welp, you're right. I must have had it mixed up with the Petit Computer SPHITRC, whoops!
    Posted
  • #9 ✎ 88 Jacklack3 Drawing I like to draw! Hobbies Day Person I like the warm sunshine and wake up early! Express Yourself Video Games I like to play video games! Hobbies How do i make a sprite detect if its touching the touch screen sprite? SPCOL and SPHITSP is not working for me. Posted