Discussions

SmileBASIC Community

ClaytonDarkClay88

07/31/2016 7:29 PM ·Spoilers

Open Closed

How do I program touching?

I need this to finish my game I'm making right now. I know it involves TOUCH STTM,TX,TY but Idk how to use it.

Advertisement

Comment

This post has no comments.

  • STTM is how long the screen has been touched. It will be 0 if the screen is not being touched. The time it returns is in hundredths seconds, I think. TX and TY simply return the position of the screen that is being touched, or the last touched if the user is no longer touching the screen. You'll probably want to place TOUCH OUT TS,TX,TY inside your main game loop to get touch info constantly.

    Yeahs0
    Played
  • Two questions. 1. The STTM is how long you have to press the screen? 2. The TX,TY is where I need to tap to make something happen?

    Yeahs0
    Played
  • I suppose you could put it that way.

    Yeahs0
    Played
  • How would I make it so if I tap anywhere on the screen, a sprite will set?

    Yeahs0
    Played
  • Well, since we know STTM tells us how long the touch screen has been touched, and that STTM is 0 if there is no touch, you could do... TOUCH OUT STTM,TX,TY IF STTM==1 THEN SPSET ?,? ...to set a sprite the very moment the touch screen is touched.

    Yeahs0
    Played
  • Interesting. I'm definitely gonna experiment this a lot like I did with some AI's. Thanks a ton!

    Yeahs0
    Played
  • How would I program so when I tap the screen in a certain location, the sprite will appear where I tapped.

    Yeahs0
    Played
  • Simple! Use TX and TY to offset your sprite accordingly. IF TS THEN 'AS LONG AS THE USER IS TOUCHING SPOFS ?,TX,TY 'LOCATE THE SPRITE AT TX, TY ENDIF

    Yeahs0
    Played
  • So it's basically saying, If STTM is 1 then the sprite should follow the touch. Its a little off but I made it to follow me. :)

    Yeahs0
    Played
  • And is there a certain collision code for touching a sprite? So like, when I tap a sprite it makes a sound?

    Yeahs0
    Played
  • That's a bit harder, but doable. Simply check if the touch coordinates match the coordinates of the sprite. If they do, play a sound. IF STTM==1 THEN SPOFS <Management#> OUT X,Y IF ABS(TX-X)<16 && ABS(TY-Y)<16 THEN BEEP ENDIF The above conditional checks if the distances between the touch's coordinates and the sprite's coordinates were within the sprites area.

    Yeahs0
    Played
  • Of course, this is assuming the sprite's size is 16x16px and its home is 0,0.

    Yeahs0
    Played
  • Interesting! I will experiment this without a doubt! Thanks so much! (You're included in the credits of my program. :) You should check it out)

    Yeahs0
    Played

Add a Comment

You must sign in to post a comment.

Sign in using a Nintendo Network ID to connect to users around the world by writing posts and comments and by giving Yeahs to other people's posts. You can create a Nintendo Network ID using your Wii U console or your system in the Nintendo 3DS family.

Use of Miiverse Details about Miiverse

Report Violation to Miiverse Administrators

You are about to report a post with content which violates the Miiverse Code of Conduct. This report will be sent to Nintendo's Miiverse administrators and not to the creator of the post.

Violation Type:

Post ID: 3DB-NBL7-EJ9-9E2A-V2W-9YJ9

Report Violation to Miiverse Administrators

You cannot report posts made automatically by a software title.

Edit Post

Select an action: