*ive never done this but im assuming you can do like*, if y=100 (lets say 100) and X=100 and button pressed() #a then (whatever you want it to do)
this is just my assumption so i might be totally wrong, or use sprite collision, if the mouse sprite is touching whatever button sprite and button is pressed then do whatever.
Yeah, if it only would allow you to use one coordinate it would be very difficult to press a button. If your buttons are sprites, then you should use TOUCH OUT TT, TX, TY to get the X and Y coordinates of the cursor, and TT will store how long it's been held. Make sure this is in a loop.
Then use SPCOL X, Y, W, H, 1 - X and Y are the offset for the top left corner of the collision box, and W and H are the width and height of it. The 1 at the end enables scale adjustment. Ideally you'll want to replace X and Y with half the width of the sprite in X, and half the height for Y, however they both should be NEGATIVE values.
Then set W and H to the width and height of the sprite, don't change these values. This will be centered around the sprite as long as you call SPHOME CN, W, H as well. For W and H here you should put half the width and height of the sprite. I forgot CN in the previous commands, that's the sprite control number so don't forget it!
Not done yet! Next you'll need to use SPHITSP(Cursor CN, F, L) within your loop, to where F and L are the first and last control numbers of the sprites you are using as buttons. HITC=SPHITSP(control numbers from before) will assign the control number of whatever sprite the cursor hits to HITC.
Lastly, if you want the buttons to activate only if they are tapped IMMEDIATELY (so you can't tap, then slide the stylus over them to activate) you'll use the value stored in TT - the touch time gained from TOUCH OUT. IF TT<2 AND HITC>-1 THEN should do the trick.
Sample of a code that would work, if I overcomplicated it:
@LOOP
TOUCH OUT TT, TX, TY
HITC=SPHITSP(0, 1, 5)
IF TT<2 AND HITC>-1 THEN
ON HITC-1 GOTO @Label for first button, label for second, etc.
ENDIF
(insert any other code you want in the loop here)
VSYNC 1:GOTO @LOOP
Replace the 1 and 5 in SPHITSP with the control numbers of your first and last button sprites.
Also make sure that you replace the 1 in ON HITC-1 with the control number of the first button sprite (if that's 5, put ON HITC-5 for example).
Button and cursor definition:
SPSET CN,U,V,W,H:SPHOME CN,W/2,H/2
SPCOL CN,-(W/2),-(H/2),W,H
Sorry, I've posted a lot just here, but I forgot that to make the cursor move to the touch coordinates, you can just put
SPOFS cursor CN, TX, TY
somewhere in the loop.
Well, it all depends on what you are using the cursor for. What I mean is, if you want to have it interact with a button that would activate once pressed and released, for example a 'confirm' button that may say OK and is supposed to close a menu when pressed, you could use a sprite that you create that appears to be said button, which makes the whole collision process a ton easier.
It's much more simple to use collision once you've figured it out - without them, all you could really do is use a whole ton of IF statements that test whether the cursor is in a particular range. With sprites, you can even make the button move and it will bring the collision range with it, meaning you could have the cursor interact with a moving button.
It basically works the same way sprites in a game would - in my game, POLYGON, the player is normally controlled with the stylus, and follows where the touch screen is being touched. Then it checks for collision with your enemies throughout the main game loop.