#1✎ 322RNGesusTouch 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 downACLS: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✎ 124kldck_hulFirst MonthJoined in the very first month of SmileBASIC SourceWebsiteScholarReceived for knowing a great deal about programming topicsAchievementsZelda Is Awesome!I love The Legend Of Zelda!Express YourselfYou 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✎ 322RNGesusYes, but that is harder to deal with AND it's not as exact.
Posted
#4✎ 124kldck_hulFirst MonthJoined in the very first month of SmileBASIC SourceWebsiteScholarReceived for knowing a great deal about programming topicsAchievementsZelda Is Awesome!I love The Legend Of Zelda!Express YourselfHow 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✎ 270NeatNitFirst WeekJoined in the very first week of SmileBASIC SourceWebsiteExpert ProgrammerProgramming no longer gives me any trouble. Come to me for help, if you like!Programming StrengthNight PersonI like the quiet night and sleep late.Express YourselfWhile 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✎ 124kldck_hulFirst MonthJoined in the very first month of SmileBASIC SourceWebsiteScholarReceived for knowing a great deal about programming topicsAchievementsZelda 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✎ 72calc84maniacOSP Contest 1 WinnerI won the first SmileBASIC Source OSP Contest!Programming ContestAmazing PageHiddenAchievementsScholarReceived for knowing a great deal about programming topicsAchievements
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✎ 270NeatNitFirst WeekJoined in the very first week of SmileBASIC SourceWebsiteExpert ProgrammerProgramming no longer gives me any trouble. Come to me for help, if you like!Programming StrengthNight PersonI 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✎ 88Jacklack3DrawingI like to draw!HobbiesDay PersonI like the warm sunshine and wake up early!Express YourselfVideo GamesI like to play video games!HobbiesHow do i make a sprite detect if its touching the touch screen sprite?
SPCOL and SPHITSP is not working for me.
Posted