? Simple TOUCH Sprite Collision Tutorial ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Simple TOUCH Sprite Collision Tutorial

What?

In this tutorial we will be creating a multi-functional TOUCH based sprite collision system in a reasonable amount of code.

What's it for?

Most games use sprites as graphics, and making any at least decent game probably will need a menu of some sort. The idea of a TOUCH based sprite selection system is to use no extra invisible sprites, this maybe key to a game that needs lots of sprites on the touch screen.

The code.

ACLS 'Resets everything prier to opening the program XSCREEN 2 'Allows us to use the touch screen DEF FUNCTION ID 'Whatever you want to do to the touched sprite here. For now we will just color it red and make all the other sprites white SPCOLOR ID,#RED 'Colors all sprites that are not the one you touched white FOR I = 0 TO 1 IF I != ID THEN SPCOLOR I,#WHITE NEXT END WHILE 1 'Changes the focused display to the touch screen DISPLAY 1 TOUCH OUT TIME,TX,TY 'Putting the touch output fro the touch screen into variables we can use 'If the time ypu spent touching is spent is more than 1 frame and its not -1(That means there is no sprite) call our function. IF TIME > 0 && SPHITRC(TX, TY, 1, 1) != -1 THEN FUNCTION SPHITRC(TX ,TY ,1, 1) ENDIF WEND That is the basic engine for anybody needing to use touch based collision. Add sprites with SPSET before the WHILE loop. Remember:You must allow collision to happen with sprites using SPCOL SpriteID or none of this will work. Please suggest improvements in the comments, it will benefit anybody looking over the page! ^_^
Author
MochaProbably
Updated
Rating
2 votes
Categories
Keywords
0 Comment(s)