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 RETURNWhat 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 STRICTWhat 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 0What 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 @LOOPWhat 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 RETURNWhat 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