LoginLogin

Using the Stylus??

Root / Programming Questions / [.]

JINC_DEVCreated:
How can I make something(anything) happen when I touch the touch screen with the stylus????

How can I make something(anything) happen when I touch the touch screen with the stylus????
TOUCH OUT T,TX,TY

How can I make something(anything) happen when I touch the touch screen with the stylus????
TOUCH OUT T,TX,TY
I've already tried that, i need more of a basic example.

WHILE 1
 TOUCH OUT T,X,Y
 IF(T!=0)THEN GCIRCLE X,Y,3,#WHITE
WEND

WHILE 1
 TOUCH OUT T,X,Y
 IF(T!=0)THEN GCIRCLE X,Y,3,#WHITE
WEND
That works great but is there a way for me to touch any where with in a box like area.

How would you check if a point is within a box normally?
IF X>=BX1 && Y>=BY1 && X<=BX2 && Y<=BY2 THEN...

How would you check if a point is within a box normally?
I don't know.

How would you check if a point is within a box normally?
I don't know.
He wasn’t asking if you know, he was giving an example in code of that situation.

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
Here'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
in that order. If all this is true, it shows the text "Touching square!" Note: When you stop touching the screen, the coordinates aren't reset. However, the time touched variable is reset to zero. This is why the circle sticks around even though we stopped touching the screen.

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.

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
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?

measure distances(distance from one point to another in 360 degrees forms a circle)
DEF DIST(X,Y,X2,Y2)
RETURN SQR(POW(X2-X,2)+POW(Y2-Y,2))'use the Pythagorean Theorem 
END