How can I make something(anything) happen when I touch the touch screen with the stylus????TOUCH OUT T,TX,TY
Using the Stylus??
Root / Programming Questions / [.]
JINC_DEVCreated:
ACLS '@1 XSCREEN 3 DISPLAY 1 X1=50:Y1=50 '@2 W1=32:H1=32 WHILE 1 '@3 VSYNC GCLS:CLS '@4 TOUCH OUT TT,TX,TY '@5 GCIRCLE TX,TY,3,#WHITE GBOX X1,Y1,X1+W1-1,Y1+H1-1,#LIME '@6 IF TT && TX>=X1 && TX<=X1+W1-1 && TY>=Y1 && TY<=Y1+H1-1 THEN:?"Touching square!" WENDHere's some sample code - but wait. It's not great to just Ctrl+C Ctrl+V the code (or in SmileBASIC's case, painstakingly type out each line), it's good to know what each line of code does. @1 This just resets the screen and lets us put stuff on the bottom screen. @2 This defines a few variables that represent a box with X and Y coordinates as well as a width and height. @3 This is just an infinite loop. @4 This sets a few variables to the touch screen coordinates. @5 This draws the box we defined in @2 and a circle around our current touch coordinates. @6 This checks to see if
- We are currently touching
- Our touched point is to the right of the left side of the box
- Our touched point is to the left of the right side of the box
- Our touched point is below the top of the box
- Our touched point is above the bottom of the box
A trick I used in Super Bearland was to make an invisible Cursor sprite that moved to wherever you touched. Everything clickable was a sprite, so all I had to do was detect sprite collision to determine if you tapped something.
A trick I used in Super Bearland was to make an invisible Cursor sprite that moved to wherever you touched. Everything clickable was a sprite, so all I had to do was detect sprite collision to determine if you tapped something.Yeah this. Makes things really easy.
I found this helpful with the touch screen, but is there a way to check if the circle is colliding with the square on the edges of the circle instead of just the middle, where the stylus is?ACLS '@1 XSCREEN 3 DISPLAY 1 X1=50:Y1=50 '@2 W1=32:H1=32 WHILE 1 '@3 VSYNC GCLS:CLS '@4 TOUCH OUT TT,TX,TY '@5 GCIRCLE TX,TY,3,#WHITE GBOX X1,Y1,X1+W1-1,Y1+H1-1,#LIME '@6 IF TT && TX>=X1 && TX<=X1+W1-1 && TY>=Y1 && TY<=Y1+H1-1 THEN:?"Touching square!" WEND